From 14a015e44a5c0c9e7e453cf13ba4bf3019f8df01 Mon Sep 17 00:00:00 2001 From: Tarun Chinmai Sekar Date: Mon, 12 Feb 2024 13:55:04 -0800 Subject: [PATCH] Fixes for bucket --- .../v1alpha1/zz_bucket_terraformed.go | 2 +- .../objectstorage/v1alpha1/zz_bucket_types.go | 26 ++++-- .../v1alpha1/zz_generated.deepcopy.go | 46 ++++++++-- cluster/test/setup.sh | 1 + config/objectstoragebucket/config.go | 12 ++- .../resources/instance/simple-instance.yaml | 2 +- examples/resources/objectstorage/bucket.yaml | 1 - go.mod | 2 +- go.sum | 4 +- internal/clients/linode.go | 3 +- ...jectstorage.linode.upbound.io_buckets.yaml | 88 ++++--------------- 11 files changed, 97 insertions(+), 90 deletions(-) diff --git a/apis/objectstorage/v1alpha1/zz_bucket_terraformed.go b/apis/objectstorage/v1alpha1/zz_bucket_terraformed.go index 52287b8..a2030d3 100755 --- a/apis/objectstorage/v1alpha1/zz_bucket_terraformed.go +++ b/apis/objectstorage/v1alpha1/zz_bucket_terraformed.go @@ -25,7 +25,7 @@ func (mg *Bucket) GetTerraformResourceType() string { // GetConnectionDetailsMapping for this Bucket func (tr *Bucket) GetConnectionDetailsMapping() map[string]string { - return map[string]string{"cert[*].certificate": "spec.forProvider.cert[*].certificateSecretRef", "cert[*].private_key": "spec.forProvider.cert[*].privateKeySecretRef"} + return nil } // GetObservation of this Bucket diff --git a/apis/objectstorage/v1alpha1/zz_bucket_types.go b/apis/objectstorage/v1alpha1/zz_bucket_types.go index 4acb7cb..7d618ce 100755 --- a/apis/objectstorage/v1alpha1/zz_bucket_types.go +++ b/apis/objectstorage/v1alpha1/zz_bucket_types.go @@ -87,7 +87,7 @@ type BucketObservation struct { AccessKey *string `json:"accessKey,omitempty" tf:"access_key,omitempty"` // The cert used by this Object Storage Bucket. - Cert []CertParameters `json:"cert,omitempty" tf:"cert,omitempty"` + Cert []CertObservation `json:"cert,omitempty" tf:"cert,omitempty"` // The cluster of the Linode Object Storage Bucket. // The cluster of the Linode Object Storage Bucket. @@ -188,22 +188,38 @@ type BucketParameters struct { } type CertInitParameters struct { + + // The Base64 encoded and PEM formatted SSL certificate. + // The Base64 encoded and PEM formatted SSL certificate. + Certificate *string `json:"certificate,omitempty" tf:"certificate,omitempty"` + + // The private key associated with the TLS/SSL certificate. + // The private key associated with the TLS/SSL certificate. + PrivateKey *string `json:"privateKey,omitempty" tf:"private_key,omitempty"` } type CertObservation struct { + + // The Base64 encoded and PEM formatted SSL certificate. + // The Base64 encoded and PEM formatted SSL certificate. + Certificate *string `json:"certificate,omitempty" tf:"certificate,omitempty"` + + // The private key associated with the TLS/SSL certificate. + // The private key associated with the TLS/SSL certificate. + PrivateKey *string `json:"privateKey,omitempty" tf:"private_key,omitempty"` } type CertParameters struct { // The Base64 encoded and PEM formatted SSL certificate. // The Base64 encoded and PEM formatted SSL certificate. - // +kubebuilder:validation:Required - CertificateSecretRef v1.SecretKeySelector `json:"certificateSecretRef" tf:"-"` + // +kubebuilder:validation:Optional + Certificate *string `json:"certificate" tf:"certificate,omitempty"` // The private key associated with the TLS/SSL certificate. // The private key associated with the TLS/SSL certificate. - // +kubebuilder:validation:Required - PrivateKeySecretRef v1.SecretKeySelector `json:"privateKeySecretRef" tf:"-"` + // +kubebuilder:validation:Optional + PrivateKey *string `json:"privateKey" tf:"private_key,omitempty"` } type ExpirationInitParameters struct { diff --git a/apis/objectstorage/v1alpha1/zz_generated.deepcopy.go b/apis/objectstorage/v1alpha1/zz_generated.deepcopy.go index ae8e9fd..9c39c24 100644 --- a/apis/objectstorage/v1alpha1/zz_generated.deepcopy.go +++ b/apis/objectstorage/v1alpha1/zz_generated.deepcopy.go @@ -156,7 +156,9 @@ func (in *BucketInitParameters) DeepCopyInto(out *BucketInitParameters) { if in.Cert != nil { in, out := &in.Cert, &out.Cert *out = make([]CertInitParameters, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.Cluster != nil { in, out := &in.Cluster, &out.Cluster @@ -259,8 +261,10 @@ func (in *BucketObservation) DeepCopyInto(out *BucketObservation) { } if in.Cert != nil { in, out := &in.Cert, &out.Cert - *out = make([]CertParameters, len(*in)) - copy(*out, *in) + *out = make([]CertObservation, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.Cluster != nil { in, out := &in.Cluster, &out.Cluster @@ -342,7 +346,9 @@ func (in *BucketParameters) DeepCopyInto(out *BucketParameters) { if in.Cert != nil { in, out := &in.Cert, &out.Cert *out = make([]CertParameters, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.Cluster != nil { in, out := &in.Cluster, &out.Cluster @@ -436,6 +442,16 @@ func (in *BucketStatus) DeepCopy() *BucketStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CertInitParameters) DeepCopyInto(out *CertInitParameters) { *out = *in + if in.Certificate != nil { + in, out := &in.Certificate, &out.Certificate + *out = new(string) + **out = **in + } + if in.PrivateKey != nil { + in, out := &in.PrivateKey, &out.PrivateKey + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CertInitParameters. @@ -451,6 +467,16 @@ func (in *CertInitParameters) DeepCopy() *CertInitParameters { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CertObservation) DeepCopyInto(out *CertObservation) { *out = *in + if in.Certificate != nil { + in, out := &in.Certificate, &out.Certificate + *out = new(string) + **out = **in + } + if in.PrivateKey != nil { + in, out := &in.PrivateKey, &out.PrivateKey + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CertObservation. @@ -466,8 +492,16 @@ func (in *CertObservation) DeepCopy() *CertObservation { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CertParameters) DeepCopyInto(out *CertParameters) { *out = *in - out.CertificateSecretRef = in.CertificateSecretRef - out.PrivateKeySecretRef = in.PrivateKeySecretRef + if in.Certificate != nil { + in, out := &in.Certificate, &out.Certificate + *out = new(string) + **out = **in + } + if in.PrivateKey != nil { + in, out := &in.PrivateKey, &out.PrivateKey + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CertParameters. diff --git a/cluster/test/setup.sh b/cluster/test/setup.sh index 6f381fd..e140b4b 100755 --- a/cluster/test/setup.sh +++ b/cluster/test/setup.sh @@ -24,3 +24,4 @@ spec: name: provider-secret namespace: upbound-system key: credentials +EOF diff --git a/config/objectstoragebucket/config.go b/config/objectstoragebucket/config.go index bf07693..fb80e08 100644 --- a/config/objectstoragebucket/config.go +++ b/config/objectstoragebucket/config.go @@ -1,13 +1,21 @@ package objectstoragebucket -import "github.com/crossplane/upjet/pkg/config" +import ( + "github.com/crossplane/upjet/pkg/config" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) // Configure configures individual resources by adding custom ResourceConfigurators. func Configure(p *config.Provider) { p.AddResourceConfigurator("linode_object_storage_bucket", func(r *config.Resource) { - r.ShortGroup = "objectstorage" r.Kind = "Bucket" + element, ok := r.TerraformResource.Schema["cert"].Elem.(*schema.Resource) + if ok { + element.Schema["certificate"].Sensitive = false + element.Schema["private_key"].Sensitive = false + } + r.References["access_key"] = config.Reference{ Type: "Key", RefFieldName: "AccessKeyRef", diff --git a/examples/resources/instance/simple-instance.yaml b/examples/resources/instance/simple-instance.yaml index 01d5526..10eb5ce 100644 --- a/examples/resources/instance/simple-instance.yaml +++ b/examples/resources/instance/simple-instance.yaml @@ -1,7 +1,7 @@ apiVersion: instance.linode.upbound.io/v1alpha1 kind: Instance metadata: - name: test-instance + name: uptest-instance spec: forProvider: image: linode/ubuntu22.04 diff --git a/examples/resources/objectstorage/bucket.yaml b/examples/resources/objectstorage/bucket.yaml index a408bcb..84ae3c3 100644 --- a/examples/resources/objectstorage/bucket.yaml +++ b/examples/resources/objectstorage/bucket.yaml @@ -5,7 +5,6 @@ metadata: spec: deletionPolicy: Orphan forProvider: - corsEnabled: true label: test-bucket cluster: us-sea-1 providerConfigRef: diff --git a/go.mod b/go.mod index f2b59e3..b7976c4 100644 --- a/go.mod +++ b/go.mod @@ -154,4 +154,4 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace github.com/linode/terraform-provider-linode/v2 v2.14.0 => github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240209230743-2ac41241b647 +replace github.com/linode/terraform-provider-linode/v2 v2.14.0 => github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240212213046-468f25b69508 diff --git a/go.sum b/go.sum index e02b0a0..d2b9160 100644 --- a/go.sum +++ b/go.sum @@ -432,8 +432,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240209230743-2ac41241b647 h1:3ws/71Hmz4NKmrYpDw1YCTOomVQRs2d5xY8h2x9UvzI= -github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240209230743-2ac41241b647/go.mod h1:aBTakKvYrwuKW1rCpFiW2pjvNnVXz3yJqUfDvtFiFOw= +github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240212213046-468f25b69508 h1:u3jh3HD6dHK1AxGDCGVg6uIAXmiGxDCgylaco9n1wX8= +github.com/tchinmai7/terraform-provider-linode/v2 v2.0.0-20240212213046-468f25b69508/go.mod h1:aBTakKvYrwuKW1rCpFiW2pjvNnVXz3yJqUfDvtFiFOw= github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ= github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= diff --git a/internal/clients/linode.go b/internal/clients/linode.go index 4aebf88..7c4f8bc 100644 --- a/internal/clients/linode.go +++ b/internal/clients/linode.go @@ -20,6 +20,7 @@ import ( "github.com/linode/provider-linode/apis/v1beta1" "github.com/linode/terraform-provider-linode/v2/linode" + "github.com/linode/terraform-provider-linode/v2/linode/helper" "github.com/linode/terraform-provider-linode/v2/version" ) @@ -115,7 +116,7 @@ func configureNoForkLinodeclient(ctx context.Context, ps *terraform.Setup, p sch ps.Meta = p.Meta() - fwProvider := linode.CreateFrameworkProviderWithMeta(version.ProviderVersion, p.Meta()) + fwProvider := linode.CreateFrameworkProviderWithMeta(version.ProviderVersion, p.Meta().(*helper.ProviderMeta)) ps.FrameworkProvider = fwProvider return nil } diff --git a/package/crds/objectstorage.linode.upbound.io_buckets.yaml b/package/crds/objectstorage.linode.upbound.io_buckets.yaml index 7f32735..68b392a 100644 --- a/package/crds/objectstorage.linode.upbound.io_buckets.yaml +++ b/package/crds/objectstorage.linode.upbound.io_buckets.yaml @@ -154,46 +154,15 @@ spec: description: The cert used by this Object Storage Bucket. items: properties: - certificateSecretRef: + certificate: description: The Base64 encoded and PEM formatted SSL certificate. The Base64 encoded and PEM formatted SSL certificate. - properties: - key: - description: The key to select. - type: string - name: - description: Name of the secret. - type: string - namespace: - description: Namespace of the secret. - type: string - required: - - key - - name - - namespace - type: object - privateKeySecretRef: + type: string + privateKey: description: The private key associated with the TLS/SSL certificate. The private key associated with the TLS/SSL certificate. - properties: - key: - description: The key to select. - type: string - name: - description: Name of the secret. - type: string - namespace: - description: Namespace of the secret. - type: string - required: - - key - - name - - namespace - type: object - required: - - certificateSecretRef - - privateKeySecretRef + type: string type: object type: array cluster: @@ -457,6 +426,16 @@ spec: cert: description: The cert used by this Object Storage Bucket. items: + properties: + certificate: + description: The Base64 encoded and PEM formatted SSL certificate. + The Base64 encoded and PEM formatted SSL certificate. + type: string + privateKey: + description: The private key associated with the TLS/SSL + certificate. The private key associated with the TLS/SSL + certificate. + type: string type: object type: array cluster: @@ -810,46 +789,15 @@ spec: description: The cert used by this Object Storage Bucket. items: properties: - certificateSecretRef: + certificate: description: The Base64 encoded and PEM formatted SSL certificate. The Base64 encoded and PEM formatted SSL certificate. - properties: - key: - description: The key to select. - type: string - name: - description: Name of the secret. - type: string - namespace: - description: Namespace of the secret. - type: string - required: - - key - - name - - namespace - type: object - privateKeySecretRef: + type: string + privateKey: description: The private key associated with the TLS/SSL certificate. The private key associated with the TLS/SSL certificate. - properties: - key: - description: The key to select. - type: string - name: - description: Name of the secret. - type: string - namespace: - description: Namespace of the secret. - type: string - required: - - key - - name - - namespace - type: object - required: - - certificateSecretRef - - privateKeySecretRef + type: string type: object type: array cluster: