Skip to content

Commit 1eb7bdf

Browse files
committed
only support external_id on vault versions >= 1.17
external_id support for aws auth sts configuration added in 1.17.0: hashicorp/vault#26628
1 parent 651c058 commit 1eb7bdf

2 files changed

+34
-9
lines changed

vault/resource_aws_auth_backend_sts_role.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ func awsAuthBackendSTSRoleCreate(d *schema.ResourceData, meta interface{}) error
7676
path := awsAuthBackendSTSRolePath(backend, accountID)
7777

7878
data := map[string]interface{}{
79-
"sts_role": stsRole,
80-
consts.FieldExternalID: externalID,
79+
"sts_role": stsRole,
80+
}
81+
82+
if provider.IsAPISupported(meta, provider.VaultVersion117) {
83+
data[consts.FieldExternalID] = externalID
8184
}
8285

8386
log.Printf("[DEBUG] Writing STS role %q to AWS auth backend", path)
@@ -128,8 +131,10 @@ func awsAuthBackendSTSRoleRead(d *schema.ResourceData, meta interface{}) error {
128131
d.Set("account_id", accountID)
129132
d.Set("sts_role", resp.Data["sts_role"])
130133

131-
if v, ok := resp.Data[consts.FieldExternalID]; ok {
132-
d.Set(consts.FieldExternalID, v)
134+
if provider.IsAPISupported(meta, provider.VaultVersion117) {
135+
if v, ok := resp.Data[consts.FieldExternalID]; ok {
136+
d.Set(consts.FieldExternalID, v)
137+
}
133138
}
134139

135140
return nil
@@ -147,8 +152,11 @@ func awsAuthBackendSTSRoleUpdate(d *schema.ResourceData, meta interface{}) error
147152
path := d.Id()
148153

149154
data := map[string]interface{}{
150-
"sts_role": stsRole,
151-
consts.FieldExternalID: externalID,
155+
"sts_role": stsRole,
156+
}
157+
158+
if provider.IsAPISupported(meta, provider.VaultVersion117) {
159+
data[consts.FieldExternalID] = externalID
152160
}
153161

154162
log.Printf("[DEBUG] Updating STS role %q in AWS auth backend", path)

vault/resource_aws_auth_backend_sts_role_test.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,35 @@ func TestAccAWSAuthBackendSTSRole_basic(t *testing.T) {
5656
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, arn, ""),
5757
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, arn),
5858
},
59+
{
60+
// Update ARN.
61+
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, updatedArn, ""),
62+
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, updatedArn),
63+
},
5964
{
6065
// Add external ID.
61-
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, arn, externalID),
62-
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, arn),
66+
SkipFunc: func() (bool, error) {
67+
meta := testProvider.Meta().(*provider.ProviderMeta)
68+
return !meta.IsAPISupported(provider.VaultVersion117), nil
69+
},
70+
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, updatedArn, externalID),
71+
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, updatedArn),
6372
},
6473
{
65-
// Update ARN and external ID.
74+
// Update external ID.
75+
SkipFunc: func() (bool, error) {
76+
meta := testProvider.Meta().(*provider.ProviderMeta)
77+
return !meta.IsAPISupported(provider.VaultVersion117), nil
78+
},
6679
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, updatedArn, updatedExternalID),
6780
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, updatedArn),
6881
},
6982
{
7083
// Remove external ID.
84+
SkipFunc: func() (bool, error) {
85+
meta := testProvider.Meta().(*provider.ProviderMeta)
86+
return !meta.IsAPISupported(provider.VaultVersion117), nil
87+
},
7188
Config: testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, updatedArn, ""),
7289
Check: testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, updatedArn),
7390
},

0 commit comments

Comments
 (0)