Skip to content

Commit

Permalink
move sts_region to 1.19 check; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcraig committed Dec 11, 2024
1 parent c0630fd commit ca2ddcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion vault/resource_aws_secret_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
var awsSecretFields = []string{
consts.FieldIAMEndpoint,
consts.FieldSTSEndpoint,
consts.FieldSTSRegion,
consts.FieldUsernameTemplate,
}

Expand Down Expand Up @@ -243,6 +242,10 @@ func awsSecretBackendCreate(ctx context.Context, d *schema.ResourceData, meta in
if v, ok := d.GetOk(consts.FieldSTSFallbackRegions); ok {
data[consts.FieldSTSFallbackRegions] = util.ToStringArray(v.([]interface{}))
}

if v, ok := d.GetOk(consts.FieldSTSRegion); ok {
data[consts.FieldSTSRegion] = v.(string)
}
}

if useAPIVer116 {
Expand Down Expand Up @@ -349,6 +352,12 @@ func awsSecretBackendRead(ctx context.Context, d *schema.ResourceData, meta inte
return diag.Errorf("error reading %s for AWS Secret Backend %q: %q", consts.FieldSTSFallbackRegions, path, err)
}
}

if v, ok := resp.Data[consts.FieldSTSRegion]; ok {
if err := d.Set(consts.FieldSTSRegion, v); err != nil {
return diag.Errorf("error reading %s for AWS Secret Backend %q: %q", consts.FieldSTSRegion, path, err)
}
}
}

if useAPIVer116 {
Expand Down Expand Up @@ -450,6 +459,10 @@ func awsSecretBackendUpdate(ctx context.Context, d *schema.ResourceData, meta in
if v, ok := d.GetOk(consts.FieldSTSFallbackRegions); ok {
data[consts.FieldSTSFallbackRegions] = util.ToStringArray(v.([]interface{}))
}

if v, ok := d.GetOk(consts.FieldSTSRegion); ok {
data[consts.FieldSTSRegion] = v.(string)
}
}

if useAPIVer116 {
Expand Down
2 changes: 2 additions & 0 deletions vault/resource_aws_secret_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func TestAccAWSSecretBackend_fallback(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, consts.FieldPath, path),
resource.TestCheckResourceAttr(resourceName, consts.FieldDescription, "test description"),
resource.TestCheckResourceAttr(resourceName, consts.FieldSTSEndpoint, "https://sts.us-west-1.amazonaws.com"),
resource.TestCheckResourceAttr(resourceName, consts.FieldSTSRegion, "us-west-1"),
resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".0", "us-east-2"),
resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".1", "us-east-1"),
resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".0", "https://sts.us-east-2.amazonaws.com"),
Expand Down

0 comments on commit ca2ddcf

Please sign in to comment.