-
Notifications
You must be signed in to change notification settings - Fork 10.3k
feat: add state_key for test run blocks #36185
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
Changes from 1 commit
3a17ab1
fd155ad
86e2ad8
ccccf62
2e497b9
877b31c
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| run "old_version" { | ||
| plan_options { | ||
| state_alias = "test1" | ||
| } | ||
| } | ||
|
|
||
| run "new_code" { | ||
| module { | ||
| source = "./breaking_change" | ||
| } | ||
| plan_options { | ||
| state_alias = "test1" | ||
| } | ||
| assert { | ||
| condition = test_resource.renamed_without_move.id == run.old_version.test_id | ||
| error_message = "resource renamed without moved block" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "test_resource" "renamed_without_move" { | ||
| value = "test" | ||
| } | ||
|
|
||
| output "test_id" { | ||
| value = test_resource.renamed_without_move.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| resource "test_resource" "test_id_moved" { | ||
| } | ||
|
|
||
| output "test_id" { | ||
| value = test_resource.test_id_moved.id | ||
| } | ||
|
|
||
| moved { | ||
| from = test_resource.test_id | ||
| to = test_resource.test_id_moved | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| run "old_version" { | ||
| module { | ||
| source = "./old_version" | ||
| } | ||
| plan_options { | ||
| state_alias = "test1" | ||
| } | ||
| } | ||
|
|
||
| run "new_code" { | ||
| plan_options { | ||
| state_alias = "test1" | ||
| } | ||
| assert { | ||
| condition = test_resource.test_id_moved.id == run.old_version.test_id | ||
| error_message = "ressource_id differed" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "test_resource" "test_id" { | ||
| value = "test" | ||
| } | ||
|
|
||
| output "test_id" { | ||
| value = test_resource.test_id.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,6 +275,8 @@ type TestRunOptions struct { | |
| // Refresh is analogous to the -refresh=false Terraform plan option. | ||
| Refresh bool | ||
|
|
||
| StateAlias string | ||
|
|
||
| // Replace is analogous to the -replace=ADDRESS Terraform plan option. | ||
| Replace []hcl.Traversal | ||
|
|
||
|
|
@@ -760,6 +762,11 @@ func decodeTestRunOptionsBlock(block *hcl.Block) (*TestRunOptions, hcl.Diagnosti | |
| opts.Target = tars | ||
| } | ||
|
|
||
| if attr, exists := content.Attributes["state_alias"]; exists { | ||
| rawDiags := gohcl.DecodeExpression(attr.Expr, nil, &opts.StateAlias) | ||
| diags = append(diags, rawDiags...) | ||
| } | ||
|
|
||
| if !opts.Refresh && opts.Mode == RefreshOnlyTestMode { | ||
| // These options are incompatible. | ||
| diags = append(diags, &hcl.Diagnostic{ | ||
|
|
@@ -839,6 +846,7 @@ var testRunOptionsBlockSchema = &hcl.BodySchema{ | |
| {Name: "refresh"}, | ||
| {Name: "replace"}, | ||
| {Name: "target"}, | ||
| {Name: "state_alias"}, | ||
|
||
| }, | ||
| } | ||
|
|
||
|
|
||
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.
I wonder if this should be
state_keyor even juststaterather thanstate_alias. Alias implies it's another name for something rather than what it's doing which is just overriding the default state key.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.
Ok i'll wait for a definitive decision on your side and i'll apply the change
I agree that it may be confusing. I was also thinking about
run_keyas mentioning the state seems weird as is never appears with terraform test