feat: ✨ Add support for assume-role block in S3 backend for Terraform#74
Conversation
| if interpolatedRoleArn != roleArn { | ||
| roleArn = interpolatedRoleArn | ||
| b["assume_role"] = fmt.Sprintf("{\"role_arn\"=\"%s\"}", roleArn) | ||
| } |
There was a problem hiding this comment.
Dead assignment to roleArn as it's local scope ends at the close of line 374. We always want the interpolated value anyhow.
| if interpolatedRoleArn != roleArn { | |
| roleArn = interpolatedRoleArn | |
| b["assume_role"] = fmt.Sprintf("{\"role_arn\"=\"%s\"}", roleArn) | |
| } | |
| if interpolatedRoleArn != roleArn { | |
| b["assume_role"] = fmt.Sprintf("{\"role_arn\"=\"%s\"}", interpolatedRoleArn) | |
| } |
There was a problem hiding this comment.
if this suggestion is taken, then line 373 will log the wrong i.e. non-interpolated value. the suggestion is the way I originally coded it.
line 370 is what preserves the correct value outside the local scope, and that is being set correctly. so this is really just semantics of how to also log the chosen value (since we want the log entry regardless of the if condition on line 369).
| // only track override config if interpolated is different from what user declared | ||
| if interpolatedBucket != bucket { | ||
| b["bucket"] = interpolatedBucket | ||
| bucket = interpolatedBucket |
There was a problem hiding this comment.
Dead assignment of bucket. Scope ends at line 387.
| bucket = interpolatedBucket |
There was a problem hiding this comment.
ditto previous comment; the var bucket is logged before the local scope ends.
| // only track override config if interpolated is different from what user declared | ||
| if interpolatedBucket != bucket { | ||
| b["bucket"] = interpolatedBucket | ||
| bucket = interpolatedBucket |
There was a problem hiding this comment.
Dead assignment of bucket. Scope ends at line 400.
| bucket = interpolatedBucket |
There was a problem hiding this comment.
ditto previous comment; the var bucket is logged before the local scope ends.
| // only track override config if interpolated is different from what user declared | ||
| if interpolatedPrefix != prefix { | ||
| b["prefix"] = interpolatedPrefix | ||
| prefix = interpolatedPrefix |
There was a problem hiding this comment.
Dead assignment of prefix. Scope ends at line 413
| prefix = interpolatedPrefix |
There was a problem hiding this comment.
ditto previous comment; the var prefix is logged before the local scope ends.
|
|
||
| require.Equal(t, S3Backend, mockResult.Type) | ||
| require.Equal(t, fmt.Sprintf("arn:aws:iam::%s:role/OrganizationAccountAccessRole", DefaultStubAccountID), mockResult.Config["role_arn"]) | ||
| require.Contains(t, mockResult.Config["assume_role"], fmt.Sprintf("arn:aws:iam::%s:role/OrganizationAccountAccessRole", DefaultStubAccountID)) |
There was a problem hiding this comment.
This test is passing, but only because the paramater happens to have the same name for its key at both the deprecated depth and the newer, nested depth. The mock backend uses the deprecated syntax but never tests the newer syntax. It also appears that the parser is not extracting the role arn value from a specific depth during initial ingestion. The regex catches and parses both cases of a role_arn value at
runiac/plugins/terraform/terraform.go
Lines 113 to 119 in 2a60147
I would suggest mocking both the deprecated syntax and the newer assume_role block as separate tests to validate behavior when encountering either one. This is also more likely to catch regressions for either case if they diverge in the future.
|
|
||
| require.Equal(t, S3Backend, mockResult.Type) | ||
| require.Equal(t, "stubrolearn", mockResult.S3RoleArn) | ||
| require.Equal(t, "stubrolearn", mockResult.AssumeRole.RoleArn) |
There was a problem hiding this comment.
The mock input is only using the deprecated syntax without interpolation. It does not validate the newer backend.assume_role.role_arn syntax.
|
I'm not entirely certain the test feedback was fully addressed before this was merged. could use follow-up if someone runs into an issue with this. 👍 |

Proposed changes
Adds support for the
assume_role = {}block that is the current syntax for assuming a role for an S3 backend in Terraform.Issues for these changes
#73
Types of changes
Checklist
README.md,CHANGELOG.md, etc. - if appropriate)Dependencies and Blockers
Relevant Links
Further comments
Note: this will break compatibility with Terraform v1.1 and below. (The
assume-roleblock was added in v1.2.) For reference, the current version of Terraform is 1.9.