Skip to content

Commit

Permalink
Fix a bug in the cloud native archival location resources (#202)
Browse files Browse the repository at this point in the history
Terraform fails to refresh the resources due to an extra level of
structure the response from RSC.
  • Loading branch information
johan3141592 authored Oct 3, 2024
1 parent d2f3482 commit 0e0a2c8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/resources/data_center_archival_location_amazon_s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "polaris_data_center_archival_location_amazon_s3" "archival_location" {
- `immutability_settings` (Block List, Max: 1) Enables immutable storage with a time-based retention lock using the AWS immutability feature for your archival location. Once enabled, you cannot delete the snapshots in this archival location before the specified immutability lock period expires. Requires an encryption password policy. (see [below for nested schema](#nestedblock--immutability_settings))
- `kms_master_key` (String) AWS KMS master key ID. Cannot be used with immutable archival locations.
- `retrieval_tier` (String) AWS bucket retrieval tier. Determines the speed and cost of retrieving data from the Glacier and Glacier Flexible Retrieval storage classes. Possible values are `BULK_TIER`, `EXPEDITED_TIER` and `STANDARD_TIER`. Default value is `STANDARD_TIER`.
- `rsa_key` (String, Sensitive) RSA key. Cannot be used with immutable archival locations.
- `rsa_key` (String, Sensitive) PEM encoded private RSA key. Cannot be used with immutable archival locations.
- `storage_class` (String) AWS bucket storage class. Possible values are `STANDARD`, `STANDARD_IA` and `ONEZONE_IA`. Default value is `STANDARD`.

### Read-Only
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.4
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.5
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.4 h1:qhGvTcLjt/FVoxixjRzwDzceeMYwRO8KEXsZuZrwhEI=
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.4/go.mod h1:ryJGDKlbaCvozY3Wvt+TPSN2OZRChQedHUNsnVfCbXE=
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.5 h1:MlF2JQh/z4QfQ1mcsiQrQwWBEvPP0PC6KCMtRPHSgbA=
github.com/rubrikinc/rubrik-polaris-sdk-for-go v0.11.0-beta.5/go.mod h1:ryJGDKlbaCvozY3Wvt+TPSN2OZRChQedHUNsnVfCbXE=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resource_aws_archival_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func awsCreateArchivalLocation(ctx context.Context, d *schema.ResourceData, m in
Name: d.Get(keyName).(string),
BucketPrefix: d.Get(keyBucketPrefix).(string),
StorageClass: d.Get(keyStorageClass).(string),
Region: aws.ParseRegionNoValidation(d.Get(keyRegion).(string)),
Region: aws.RegionFromName(d.Get(keyRegion).(string)).ToRegionEnum(),
KmsMasterKey: d.Get(keyKMSMasterKey).(string),
BucketTags: toAWSBucketTags(d.Get(keyBucketTags).(map[string]any)),
})
Expand Down Expand Up @@ -202,7 +202,7 @@ func awsReadArchivalLocation(ctx context.Context, d *schema.ResourceData, m inte
if err := d.Set(keyBucketPrefix, strings.TrimPrefix(targetTemplate.BucketPrefix, implicitPrefix)); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyConnectionStatus, targetMapping.ConnectionStatus); err != nil {
if err := d.Set(keyConnectionStatus, targetMapping.ConnectionStatus.Status); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyKMSMasterKey, targetTemplate.KMSMasterKey); err != nil {
Expand All @@ -214,7 +214,7 @@ func awsReadArchivalLocation(ctx context.Context, d *schema.ResourceData, m inte
if err := d.Set(keyName, targetMapping.Name); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyRegion, targetTemplate.Region); err != nil {
if err := d.Set(keyRegion, targetTemplate.Region.Name()); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyStorageClass, targetTemplate.StorageClass); err != nil {
Expand Down
16 changes: 2 additions & 14 deletions internal/provider/resource_azure_archival_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func azureCreateArchivalLocation(ctx context.Context, d *schema.ResourceData, m
Redundancy: d.Get(keyRedundancy).(string),
StorageTier: d.Get(keyStorageTier).(string),
StorageAccountName: d.Get(keyStorageAccountNamePrefix).(string),
StorageAccountRegion: toAzureStorageAccountRegion(d.Get(keyStorageAccountRegion).(string)),
StorageAccountRegion: azure.RegionFromName(d.Get(keyStorageAccountRegion).(string)).ToRegionEnum(),
StorageAccountTags: storageAccountTags,
CMKInfo: toAzureCustomerManagedKeys(d.Get(keyCustomerManagedKey).(*schema.Set)),
})
Expand Down Expand Up @@ -219,7 +219,7 @@ func azureReadArchivalLocation(ctx context.Context, d *schema.ResourceData, m in

targetTemplate := targetMapping.TargetTemplate
cloudNativeCompanion := targetTemplate.CloudNativeCompanion
if err := d.Set(keyConnectionStatus, targetMapping.ConnectionStatus); err != nil {
if err := d.Set(keyConnectionStatus, targetMapping.ConnectionStatus.Status); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyContainerName, targetTemplate.ContainerNamePrefix); err != nil {
Expand Down Expand Up @@ -381,15 +381,3 @@ func fromAzureStorageAccountTags(storageAccountTags []azure.Tag) map[string]any

return tags
}

// toAzureStorageAccountRegion converts from the storage account region field
// type to the Azure region enum type. If no region is specified, nil is
// returned.
func toAzureStorageAccountRegion(region string) *azure.RegionEnum {
if storageAccountRegion := azure.RegionFromName(region); storageAccountRegion != azure.RegionUnknown {
regionEnum := storageAccountRegion.ToRegionEnum()
return &regionEnum
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func resourceDataCenterArchivalLocationAmazonS3() *schema.Resource {
Optional: true,
Sensitive: true,
ExactlyOneOf: []string{keyEncryptionPassword, keyKMSMasterKey},
Description: "RSA key. Cannot be used with immutable archival locations.",
Description: "PEM encoded private RSA key. Cannot be used with immutable archival locations.",
ValidateFunc: validation.StringIsNotWhiteSpace,
},
keyStorageClass: {
Expand Down Expand Up @@ -367,7 +367,7 @@ func dataCenterCreateArchivalLocationAmazonS3(ctx context.Context, d *schema.Res
ClusterID: clusterID,
CloudAccountID: cloudAccountID,
BucketName: d.Get(keyBucketName).(string),
Region: aws.ParseRegionNoValidation(d.Get(keyRegion).(string)),
Region: aws.RegionFromName(d.Get(keyRegion).(string)).ToRegionEnum(),
StorageClass: d.Get(keyStorageClass).(string),
RetrievalTier: d.Get(keyRetrievalTier).(string),
KMSMasterKeyID: d.Get(keyKMSMasterKey).(string),
Expand Down Expand Up @@ -429,7 +429,7 @@ func dataCenterReadArchivalLocationAmazonS3(ctx context.Context, d *schema.Resou
if err := d.Set(keyBucketName, target.Bucket); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyRegion, aws.FormatRegion(target.Region)); err != nil {
if err := d.Set(keyRegion, target.Region.Name()); err != nil {
return diag.FromErr(err)
}
if err := d.Set(keyStorageClass, target.StorageClass); err != nil {
Expand Down

0 comments on commit 0e0a2c8

Please sign in to comment.