-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws_secret_backend_role: support role_arns argument #407
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7207d43
aws_secret_backend_role: add role_arns argument
anatolebeuzon 0ca3c86
aws_secret_backend_role: use role_arns in tests
anatolebeuzon 5176afb
aws_secret_backend_role: add role_arns to docs
anatolebeuzon c26f014
Merge pull request #1 from DataDog/anatole/add-role-arns
oxlay 88ff545
Remove ConflictsWith clause for policy_document
anatolebeuzon dc957f6
Remove ConflictsWith clause with policy_document for role_arns
anatolebeuzon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ func awsSecretBackendRoleResource() *schema.Resource { | |
"policy_arns": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ConflictsWith: []string{"policy", "policy_arn"}, | ||
ConflictsWith: []string{"policy", "policy_arn", "role_arns"}, | ||
Description: "ARN for an existing IAM policy the role should use.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
|
@@ -46,7 +46,7 @@ func awsSecretBackendRoleResource() *schema.Resource { | |
"policy_arn": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ConflictsWith: []string{"policy_document", "policy", "policy_arns"}, | ||
ConflictsWith: []string{"policy_document", "policy", "policy_arns", "role_arns"}, | ||
Description: "ARN for an existing IAM policy the role should use.", | ||
Deprecated: `Use "policy_arns".`, | ||
}, | ||
|
@@ -60,7 +60,7 @@ func awsSecretBackendRoleResource() *schema.Resource { | |
"policy": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ConflictsWith: []string{"policy_arns", "policy_arn", "policy_document"}, | ||
ConflictsWith: []string{"policy_arns", "policy_arn", "policy_document", "role_arns"}, | ||
Description: "IAM policy the role should use in JSON format.", | ||
DiffSuppressFunc: util.JsonDiffSuppress, | ||
Deprecated: `Use "policy_document".`, | ||
|
@@ -70,6 +70,16 @@ func awsSecretBackendRoleResource() *schema.Resource { | |
Required: true, | ||
Description: "Role credential type.", | ||
}, | ||
"role_arns": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"policy", "policy_arn", "policy_arns"}, | ||
Description: "ARNs of AWS roles allowed to be assumed. Only valid when credential_type is 'assumed_role'", | ||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -97,8 +107,14 @@ func awsSecretBackendRoleWrite(d *schema.ResourceData, meta interface{}) error { | |
policy = d.Get("policy") | ||
} | ||
|
||
if policy == "" && len(policyARNs) == 0 { | ||
return fmt.Errorf("either policy or policy_arn must be set.") | ||
var roleARNs []string | ||
roleARNsIfc := d.Get("role_arns") | ||
for _, roleIfc := range roleARNsIfc.([]interface{}) { | ||
roleARNs = append(roleARNs, roleIfc.(string)) | ||
} | ||
|
||
if policy == "" && len(policyARNs) == 0 && len(roleARNs) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this check is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you talking about the whole |
||
return fmt.Errorf("either policy, policy_arns, or role_arns must be set") | ||
} | ||
|
||
data := map[string]interface{}{ | ||
|
@@ -110,6 +126,9 @@ func awsSecretBackendRoleWrite(d *schema.ResourceData, meta interface{}) error { | |
if len(policyARNs) != 0 { | ||
data["policy_arns"] = policyARNs | ||
} | ||
if len(roleARNs) != 0 { | ||
data["role_arns"] = roleARNs | ||
} | ||
|
||
log.Printf("[DEBUG] Creating role %q on AWS backend %q", name, backend) | ||
_, err := client.Logical().Write(backend+"/roles/"+name, data) | ||
|
@@ -160,6 +179,7 @@ func awsSecretBackendRoleRead(d *schema.ResourceData, meta interface{}) error { | |
} | ||
|
||
d.Set("credential_type", secret.Data["credential_type"]) | ||
d.Set("role_arns", secret.Data["role_arns"]) | ||
d.Set("backend", strings.Join(pathPieces[:len(pathPieces)-2], "/")) | ||
d.Set("name", pathPieces[len(pathPieces)-1]) | ||
return nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do
role_arns
conflict with other fields in practice? The documentation doesn't say it does. Should we remove it from the conflicts with clauses?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
policy_document
apparently does not conflict withrole_arns
(see test using both), so I've removed the ConflictsWith clause for this onepolicy_arns
andpolicy_arn
are only valid whencredential_type
isiam_user
, whilerole_arns
is only valid whencredential_type
isassumed_role
and prohibited otherwise (per the doc), so in practice, they are mutually exclusivepolicy
, the doc says "cannot be mixed with the parameters listed above", hence theConflictsWith
clause