-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
#667 iam_role parsing before evaluation of other HCL blocks #1807
Changes from 18 commits
49121c6
cd9c5ef
4566149
60b8f91
870009c
ef63daa
fcbe185
61f9bf6
88d2f58
756cce8
606612f
0eb1cb5
b57bf54
8ad9b93
5485272
728a7d2
1a95205
118ef94
2db4e5b
3efe7f4
3129a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,19 +591,22 @@ Output: | |
$ terragrunt init | ||
uuid1 b48379e1-924d-2403-8789-c72d50be964c | ||
uuid1 9f3a8398-b11f-5314-7783-dad176ee487d | ||
uuid1 649ac501-e5db-c935-1499-c59fb7a75625 | ||
uuid2 2d65972b-3fa9-181f-64fe-dcd574d944d0 | ||
uuid3 e345de60-9cfa-0455-79b7-af0d053a15a5 | ||
potato | ||
uuid3 7f90a4ed-96e3-1dd8-5fee-91b8c8e07650 | ||
uuid2 8638fe79-c589-bebd-2a2a-3e6b96f7fc34 | ||
uuid3 310d0447-f0a6-3f67-efda-e6b1521fa1fb | ||
uuid4 f8e80cc6-1892-8db7-bd63-6089fef00c01 | ||
uuid2 289ff371-8021-54c6-2254-72de9d11392a | ||
uuid3 baa19863-1d99-e0ef-11f2-ede830d1c58a | ||
carrot | ||
``` | ||
**Notes:** | ||
* Output contains only once `carrot` and `potato`, because other invocations got cached, caching works for all sections | ||
* Output contains twice `uuid1` and `uuid2` because during HCL evaluation each `run_cmd` in `locals` section is evaluated twice, and value is cached under different key since `uuid()` add random value in key | ||
* Output contains three times `uuid3` - 2 prints because `uuid3` was declared in `locals`, once because it is declared in `inputs` | ||
* Output contains multiple times `uuid1` and `uuid2` because during HCL evaluation each `run_cmd` in `locals` is evaluated multiple times and random argument generated from `uuid()` save cached value under different key each time | ||
* Output contains multiple times `uuid3`, +1 more output comparing to `uuid1` and `uuid2` - because `uuid3` is declared in locals and inputs which add one more evaluation | ||
Comment on lines
+611
to
+612
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. NIT: are these changes related to this PR? 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. Yes. It's the result of the change in the parsing order. |
||
* Output contains only once `uuid4` since it is declared only once in `inputs`, `inputs` is not evaluated twice | ||
|
||
## read\_terragrunt\_config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
backend "local" {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
iam_role = "arn:aws:iam::666666666666:role/terragrunttest" | ||
|
||
remote_state { | ||
backend = "local" | ||
generate = { | ||
// state file should load value from iam_role | ||
path = "${get_aws_account_id()}.txt" | ||
if_exists = "overwrite" | ||
} | ||
config = { | ||
path = "terraform.tfstate" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ const ( | |
TEST_FIXTURE_LOCAL_RUN_MULTIPLE = "fixture-locals/run-multiple" | ||
TEST_FIXTURE_LOCALS_IN_INCLUDE_CHILD_REL_PATH = "qa/my-app" | ||
TEST_FIXTURE_READ_CONFIG = "fixture-read-config" | ||
TEST_FIXTURE_READ_IAM_ROLE = "fixture-read-config/iam_role_in_file" | ||
TEST_FIXTURE_AWS_GET_CALLER_IDENTITY = "fixture-get-aws-caller-identity" | ||
TEST_FIXTURE_GET_PLATFORM = "fixture-get-platform" | ||
TEST_FIXTURE_GET_TERRAGRUNT_SOURCE_HCL = "fixture-get-terragrunt-source-hcl" | ||
|
@@ -3623,6 +3624,32 @@ func TestTerragruntVersionConstraints(t *testing.T) { | |
} | ||
} | ||
|
||
func TestReadTerragruntConfigIamRole(t *testing.T) { | ||
t.Parallel() | ||
|
||
identityArn, err := aws_helper.GetAWSIdentityArn(nil, &options.TerragruntOptions{ | ||
IamRole: "", | ||
}) | ||
assert.NoError(t, err) | ||
|
||
cleanupTerraformFolder(t, TEST_FIXTURE_READ_IAM_ROLE) | ||
|
||
// Execution outputs to be verified | ||
stdout := bytes.Buffer{} | ||
stderr := bytes.Buffer{} | ||
|
||
// Invoke terragrunt and verify used IAM role | ||
err = runTerragruntCommand(t, fmt.Sprintf("terragrunt init --terragrunt-working-dir %s", TEST_FIXTURE_READ_IAM_ROLE), &stdout, &stderr) | ||
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. Will this actually try to assume the fake IAM role and lead to a permissions error? 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. Yes, and it will fail to create state file with IAM role ID |
||
|
||
// Since are used not existing AWS accounts, for validation are used success and error outputs | ||
output := fmt.Sprintf("%v %v %v", string(stderr.Bytes()), string(stdout.Bytes()), err.Error()) | ||
|
||
// Check that output contains value defined in IAM role | ||
assert.Equal(t, 1, strings.Count(output, "666666666666")) | ||
// Ensure that state file wasn't created with default IAM value | ||
assert.True(t, util.FileNotExists(util.JoinPath(TEST_FIXTURE_READ_IAM_ROLE, identityArn+".txt"))) | ||
} | ||
|
||
func TestTerragruntVersionConstraintsPartialParse(t *testing.T) { | ||
fixturePath := "fixture-partial-parse/terragrunt-version-constraint" | ||
cleanupTerragruntFolder(t, fixturePath) | ||
|
@@ -4304,9 +4331,9 @@ func TestTerragruntInitRunCmd(t *testing.T) { | |
assert.Equal(t, 1, strings.Count(errout, "input_variable")) | ||
|
||
// Commands executed multiple times because of different arguments | ||
assert.Equal(t, 3, strings.Count(errout, "uuid")) | ||
assert.Equal(t, 4, strings.Count(errout, "random_arg")) | ||
assert.Equal(t, 3, strings.Count(errout, "another_arg")) | ||
assert.Equal(t, 4, strings.Count(errout, "uuid")) | ||
assert.Equal(t, 6, strings.Count(errout, "random_arg")) | ||
assert.Equal(t, 4, strings.Count(errout, "another_arg")) | ||
} | ||
|
||
func TestNoFailureForModulesWithoutOutputs(t *testing.T) { | ||
|
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.
NIT: Rename to
setIAMRole
, to indicate that this function has side effects (modifying attribute onterragruntOptions
.