-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QTI-236] Resolve non-constant step variable index expressions (#44)
In order to pass information between modules, we have to convert step variable expressions into absolute traversals if we don't know the value of them. HCL only supports converting an expression into an absolute traversal if all traversals have constant keys. This works fine if you use static values, but in cases where you want to refer to variables or matrix variants it would break, e.g.: ```hcl matrix { arch = ["arm64", "amd64"] distro = ["rhel", "ubuntu"] } step "infra" { // Exports an "ami" output that is complex map } step "two" { variables { input = step.one[matrix.distro][matrix.arch] } } ``` Now we attempt to resolve the non-constant keys in index expressions so that we can render an absolute traversal. Signed-off-by: Ryan Cragun <[email protected]>
- Loading branch information
1 parent
22cfe63
commit 440b798
Showing
5 changed files
with
117 additions
and
3 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module "infra" { | ||
source = "./modules/infra" | ||
} | ||
|
||
module "target" { | ||
source = "./modules/target" | ||
} | ||
|
||
scenario "step_vars" { | ||
matrix { | ||
distro = ["ubuntu", "rhel"] | ||
arch = ["arm", "amd"] | ||
} | ||
|
||
step "infra" { | ||
module = module.infra | ||
} | ||
|
||
step "target" { | ||
module = module.target | ||
|
||
variables { | ||
ami = step.infra.amis[matrix.distro][matrix.arch] | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
acceptance/scenarios/scenario_generate_step_vars/modules/infra/output.tf
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
output "amis" { | ||
value = { | ||
"ubuntu" = { | ||
"arm" = "ubuntu-arm" | ||
"amd" = "ubuntu-amd" | ||
} | ||
"rhel" = { | ||
"arm" = "rhel-arm" | ||
"amd" = "rhel-amd" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
acceptance/scenarios/scenario_generate_step_vars/modules/target/input.tf
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "ami" { | ||
type = string | ||
} |
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