Skip to content

Commit

Permalink
Merge pull request #9 from tatsuo48/take_care_of_recursive_module
Browse files Browse the repository at this point in the history
Take care of recursive module
  • Loading branch information
fujiwara authored Aug 17, 2020
2 parents 6da1fba + 7bc6122 commit b0f9577
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tfstate/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ func parseAddress(key string) (selectorFunc, string, error) {

var module string
if parts[0] == "module" {
module = "module." + parts[1]
parts = parts[2:] // remove module prefix
for i := len(parts) - 1; i >= 0; i-- {
if parts[i] == "module" {
module = strings.Join(parts[0:i+2], ".")
parts = parts[i+2:] // remove module prefix
break
}
}
}
if parts[0] == "data" {
selector = func(r resource) *instance {
Expand Down
13 changes: 13 additions & 0 deletions tfstate/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var TestNames = []string{
`module.logs.aws_cloudwatch_log_group.main["web"]`,
`aws_iam_role_policy_attachment.ec2[0]`,
`aws_iam_role_policy_attachment.ec2[1]`,
`module.webapp.module.ecs_task_roles.aws_iam_role.task_execution_role`,
}

var TestSuitesOK = []TestSuite{
Expand Down Expand Up @@ -97,6 +98,18 @@ var TestSuitesOK = []TestSuite{
Key: `output.baz.value`,
Result: nil,
},
TestSuite{
Key: "module.webapp.module.ecs_task_roles.aws_iam_role.task_execution_role.name",
Result: "task-execution-role",
},
TestSuite{
Key: "module.webapp.xxxx.ecs_task_roles.aws_iam_role.task_execution_role",
Result: nil,
},
TestSuite{
Key: "xxxx.webapp.module.ecs_task_roles.aws_iam_role.task_execution_role",
Result: nil,
},
}

func TestLookupOK(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions tfstate/test/terraform.tfstate
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@
"private": "bnVsbA=="
}
]
},
{
"module": "module.webapp.module.ecs_task_roles",
"mode": "managed",
"type": "aws_iam_role",
"name": "task_execution_role",
"provider": "provider.aws",
"instances": [
{
"schema_version": 0,
"attributes": {
"arn": "arn:aws:iam::123456789012:role/task-execution-role",
"assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ecs-tasks.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}",
"create_date": "2019-11-18T07:57:06Z",
"description": "",
"force_detach_policies": false,
"id": "task-execution-role",
"max_session_duration": 3600,
"name": "task-execution-role",
"name_prefix": null,
"path": "/",
"permissions_boundary": null,
"tags": {},
"unique_id": "AAAAAAAAAAAA"
},
"private": "bnVsbA=="
}
]
}
]
}

0 comments on commit b0f9577

Please sign in to comment.