Skip to content
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

wip f: additional attribute source_identity for assume_role #25368

Merged
merged 4 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25368.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
provider: Add `source_identity` argument to `assume_role` block
```
5 changes: 5 additions & 0 deletions internal/provider/fwprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ func (p *fwprovider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnost
Optional: true,
Description: "An identifier for the assumed role session.",
},
"source_identity": {
Type: types.StringType,
Optional: true,
Description: "Source identity specified by the principal assuming the role.",
},
"tags": {
Type: types.MapType{ElemType: types.StringType},
Optional: true,
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer

if l, ok := d.Get("assume_role").([]interface{}); ok && len(l) > 0 && l[0] != nil {
config.AssumeRole = expandAssumeRole(l[0].(map[string]interface{}))
log.Printf("[INFO] assume_role configuration set: (ARN: %q, SessionID: %q, ExternalID: %q)", config.AssumeRole.RoleARN, config.AssumeRole.SessionName, config.AssumeRole.ExternalID)
log.Printf("[INFO] assume_role configuration set: (ARN: %q, SessionID: %q, ExternalID: %q, SourceIdentity: %q)", config.AssumeRole.RoleARN, config.AssumeRole.SessionName, config.AssumeRole.ExternalID, config.AssumeRole.SourceIdentity)
}

if l, ok := d.Get("assume_role_with_web_identity").([]interface{}); ok && len(l) > 0 && l[0] != nil {
Expand Down Expand Up @@ -2304,6 +2304,12 @@ func assumeRoleSchema() *schema.Schema {
Description: "An identifier for the assumed role session.",
ValidateFunc: validAssumeRoleSessionName,
},
"source_identity": {
Type: schema.TypeString,
Optional: true,
Description: "Source identity specified by the principal assuming the role.",
ValidateFunc: validAssumeRoleSourceIdentity,
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -2438,6 +2444,10 @@ func expandAssumeRole(m map[string]interface{}) *awsbase.AssumeRole {
assumeRole.SessionName = v
}

if v, ok := m["source_identity"].(string); ok && v != "" {
assumeRole.SourceIdentity = v
}

if tagMapRaw, ok := m["tags"].(map[string]interface{}); ok && len(tagMapRaw) > 0 {
assumeRole.Tags = make(map[string]string)

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ var validAssumeRoleSessionName = validation.All(
validation.StringLenBetween(2, 64),
validation.StringMatch(regexp.MustCompile(`[\w+=,.@\-]*`), ""),
)

var validAssumeRoleSourceIdentity = validation.All(
validation.StringLenBetween(2, 64),
validation.StringMatch(regexp.MustCompile(`[\w+=,.@\-]*`), ""),
)
22 changes: 16 additions & 6 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ See the [assume role documentation](https://docs.aws.amazon.com/cli/latest/userg
|Policy|`policy`|N/A|
|Policy ARNs|`policy_arns`|N/A|
|Session Name|`session_name`|`role_session_name`|
|Source Identity|`source_identity`|N/A|
|Tags|`tags`|N/A|
|Transitive Tag Keys|`transitive_tag_keys`|N/A|

Expand Down Expand Up @@ -459,29 +460,38 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf

The `assume_role` configuration block supports the following arguments:

* `duration` - (Optional, Conflicts with `duration_seconds`) Duration of the assume role session. You can provide a value from 15 minutes up to the maximum session duration setting for the role. Represented by a string such as `1h`, `2h45m`, or `30m15s`.
* `duration_seconds` - (Optional, **Deprecated** use `duration` instead) Number of seconds to restrict the assume role session duration. You can provide a value from 900 seconds (15 minutes) up to the maximum session duration setting for the role.
* `duration` - (Optional, Conflicts with `duration_seconds`) Duration of the assume role session.
You can provide a value from 15 minutes up to the maximum session duration setting for the role.
Represented by a string such as `1h`, `2h45m`, or `30m15s`.
* `duration_seconds` - (Optional, **Deprecated** use `duration` instead) Number of seconds to restrict the assume role session duration.
You can provide a value from 900 seconds (15 minutes) up to the maximum session duration setting for the role.
* `external_id` - (Optional) External identifier to use when assuming the role.
* `policy` - (Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.
* `policy_arns` - (Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.
* `role_arn` - (Required) ARN of the IAM Role to assume.
* `session_name` - (Optional) Session name to use when assuming the role.
* `source_identity` - (Optional) Source identity specified by the principal assuming the role.
* `tags` - (Optional) Map of assume role session tags.
* `transitive_tag_keys` - (Optional) Set of assume role session tag keys to pass to any subsequent sessions.

### assume_role_with_web_identity Configuration Block

The `assume_role_with_web_identity` configuration block supports the following arguments:

* `duration` - (Optional) Duration of the assume role session. You can provide a value from 15 minutes up to the maximum session duration setting for the role. Represented by a string such as `1h`, `2h45m`, or `30m15s`.
* `duration` - (Optional) Duration of the assume role session.
You can provide a value from 15 minutes up to the maximum session duration setting for the role.
Represented by a string such as `1h`, `2h45m`, or `30m15s`.
* `policy` - (Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.
* `policy_arns` - (Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.
* `role_arn` - (Required) ARN of the IAM Role to assume. Can also be set with the `AWS_ROLE_ARN` environment variable.
* `session_name` - (Optional) Session name to use when assuming the role. Can also be set with the `AWS_ROLE_SESSION_NAME` environment variable.
* `role_arn` - (Required) ARN of the IAM Role to assume.
Can also be set with the `AWS_ROLE_ARN` environment variable.
* `session_name` - (Optional) Session name to use when assuming the role.
Can also be set with the `AWS_ROLE_SESSION_NAME` environment variable.
* `web_identity_token` - (Optional) Value of a web identity token from an OpenID Connect (OIDC) or OAuth provider.
One of `web_identity_token` or `web_identity_token_file` is required.
* `web_identity_token_file` - (Optional) File containing a web identity token from an OpenID Connect (OIDC) or OAuth provider.
One of `web_identity_token_file` or `web_identity_token` is required. Can also be set with the `AWS_WEB_IDENTITY_TOKEN_FILE` environment variable.
One of `web_identity_token_file` or `web_identity_token` is required.
Can also be set with the `AWS_WEB_IDENTITY_TOKEN_FILE` environment variable.

### default_tags Configuration Block

Expand Down