|
5 | 5 | package s3 |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + xpresource "github.com/crossplane/crossplane-runtime/v2/pkg/resource" |
8 | 9 | "github.com/crossplane/upjet/v2/pkg/config" |
| 10 | + "github.com/crossplane/upjet/v2/pkg/config/conversion" |
9 | 11 | "github.com/crossplane/upjet/v2/pkg/registry" |
10 | 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 13 | + "github.com/upbound/provider-aws/apis/cluster/s3/v1beta1" |
| 14 | + "github.com/upbound/provider-aws/apis/cluster/s3/v1beta2" |
11 | 15 | ) |
12 | 16 |
|
13 | 17 | // Configure adds configurations for the s3 group. |
@@ -53,6 +57,10 @@ func Configure(p *config.Provider) { //nolint:gocyclo |
53 | 57 | } |
54 | 58 | return nil |
55 | 59 | } |
| 60 | + r.Conversions = append(r.Conversions, |
| 61 | + conversion.NewCustomConverter("v1beta1", "v1beta2", bucketConverterFromv1beta1Tov1beta2), |
| 62 | + conversion.NewCustomConverter("v1beta2", "v1beta1", bucketConverterFromv1beta2Tov1beta1), |
| 63 | + ) |
56 | 64 | }) |
57 | 65 |
|
58 | 66 | p.AddResourceConfigurator("aws_s3_bucket_acl", func(r *config.Resource) { |
@@ -136,3 +144,65 @@ func Configure(p *config.Provider) { //nolint:gocyclo |
136 | 144 | } |
137 | 145 | }) |
138 | 146 | } |
| 147 | + |
| 148 | +func bucketConverterFromv1beta1Tov1beta2(src, target xpresource.Managed) error { |
| 149 | + srcTyped := src.(*v1beta1.Bucket) |
| 150 | + targetTyped := target.(*v1beta2.Bucket) |
| 151 | + |
| 152 | + if len(srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration) > 0 { |
| 153 | + if targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration == nil { |
| 154 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration = &v1beta2.ServerSideEncryptionConfigurationObservation{} |
| 155 | + } |
| 156 | + if len(srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule) > 0 { |
| 157 | + if targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule == nil { |
| 158 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule = &v1beta2.ServerSideEncryptionConfigurationRuleObservation{} |
| 159 | + } |
| 160 | + if len(srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault) > 0 { |
| 161 | + if targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault == nil { |
| 162 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault = &v1beta2.ApplyServerSideEncryptionByDefaultObservation{} |
| 163 | + } |
| 164 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].KMSMasterKeyID != nil { |
| 165 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.KMSMasterKeyID = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].KMSMasterKeyID |
| 166 | + } |
| 167 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].SseAlgorithm != nil { |
| 168 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.SseAlgorithm = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].SseAlgorithm |
| 169 | + } |
| 170 | + } |
| 171 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].BucketKeyEnabled != nil { |
| 172 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.BucketKeyEnabled = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].BucketKeyEnabled |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + return nil |
| 177 | +} |
| 178 | + |
| 179 | +func bucketConverterFromv1beta2Tov1beta1(src, target xpresource.Managed) error { |
| 180 | + srcTyped := src.(*v1beta2.Bucket) |
| 181 | + targetTyped := target.(*v1beta1.Bucket) |
| 182 | + |
| 183 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration != nil { |
| 184 | + if len(targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration) == 0 { |
| 185 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration = []v1beta1.ServerSideEncryptionConfigurationObservation{{}} |
| 186 | + } |
| 187 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule != nil { |
| 188 | + if len(targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule) == 0 { |
| 189 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule = []v1beta1.ServerSideEncryptionConfigurationRuleObservation{{}} |
| 190 | + } |
| 191 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault != nil { |
| 192 | + if len(targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault) == 0 { |
| 193 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault = []v1beta1.ApplyServerSideEncryptionByDefaultObservation{{}} |
| 194 | + } |
| 195 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.KMSMasterKeyID != nil { |
| 196 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].KMSMasterKeyID = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.KMSMasterKeyID |
| 197 | + } |
| 198 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.SseAlgorithm != nil { |
| 199 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].ApplyServerSideEncryptionByDefault[0].SseAlgorithm = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.ApplyServerSideEncryptionByDefault.SseAlgorithm |
| 200 | + } |
| 201 | + } |
| 202 | + if srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.BucketKeyEnabled != nil { |
| 203 | + targetTyped.Status.AtProvider.ServerSideEncryptionConfiguration[0].Rule[0].BucketKeyEnabled = srcTyped.Status.AtProvider.ServerSideEncryptionConfiguration.Rule.BucketKeyEnabled |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + return nil |
| 208 | +} |
0 commit comments