Skip to content

Commit

Permalink
add tests showing expected prior state resource addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
mildwonkey committed Mar 3, 2020
1 parent cf0de77 commit a16a753
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 4 deletions.
4 changes: 0 additions & 4 deletions command/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ func TestShow_json_output(t *testing.T) {
if !cmp.Equal(got, want) {
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
}

})

}
}

Expand Down Expand Up @@ -405,9 +403,7 @@ func TestShow_json_output_state(t *testing.T) {
if !cmp.Equal(got, want) {
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
}

})

}
}

Expand Down
36 changes: 36 additions & 0 deletions command/testdata/show-json-state/basic/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"format_version": "0.1",
"terraform_version": "0.12.21",
"values": {
"root_module": {
"resources": [
{
"address": "test_instance.example[0]",
"mode": "managed",
"type": "test_instance",
"name": "example",
"index": 0,
"provider_name": "test",
"schema_version": 0,
"values": {
"ami": null,
"id": "621124146446964903"
}
},
{
"address": "test_instance.example[1]",
"mode": "managed",
"type": "test_instance",
"name": "example",
"index": 1,
"provider_name": "test",
"schema_version": 0,
"values": {
"ami": null,
"id": "4330206298367988603"
}
}
]
}
}
}
34 changes: 34 additions & 0 deletions command/testdata/show-json-state/basic/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 4,
"terraform_version": "0.12.0",
"serial": 1,
"lineage": "00bfda35-ad61-ec8d-c013-14b0320bc416",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "test_instance",
"name": "example",
"each": "list",
"provider": "provider.test",
"instances": [
{
"index_key": 0,
"schema_version": 0,
"attributes": {
"id": "621124146446964903"
},
"private": "bnVsbA=="
},
{
"index_key": 1,
"schema_version": 0,
"attributes": {
"id": "4330206298367988603"
},
"private": "bnVsbA=="
}
]
}
]
}
13 changes: 13 additions & 0 deletions command/testdata/show-json/multi-resource-update/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "test_var" {
default = "bar"
}

// There is a single instance in state. The plan will add a resource.
resource "test_instance" "test" {
ami = var.test_var
count = 2
}

output "test" {
value = var.test_var
}
167 changes: 167 additions & 0 deletions command/testdata/show-json/multi-resource-update/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"format_version": "0.1",
"terraform_version": "0.13.0",
"variables": {
"test_var": {
"value": "bar"
}
},
"planned_values": {
"outputs": {
"test": {
"sensitive": false,
"value": "bar"
}
},
"root_module": {
"resources": [
{
"address": "test_instance.test[0]",
"mode": "managed",
"type": "test_instance",
"name": "test",
"index": 0,
"provider_name": "test",
"schema_version": 0,
"values": {
"ami": "bar",
"id": "placeholder"
}
},
{
"address": "test_instance.test[1]",
"mode": "managed",
"type": "test_instance",
"name": "test",
"index": 1,
"provider_name": "test",
"schema_version": 0,
"values": {
"ami": "bar"
}
}
]
}
},
"resource_changes": [
{
"address": "test_instance.test[0]",
"mode": "managed",
"type": "test_instance",
"name": "test",
"index": 0,
"provider_name": "test",
"change": {
"actions": [
"no-op"
],
"before": {
"ami": "bar",
"id": "placeholder"
},
"after": {
"ami": "bar",
"id": "placeholder"
},
"after_unknown": {}
}
},
{
"address": "test_instance.test[1]",
"mode": "managed",
"type": "test_instance",
"name": "test",
"index": 1,
"provider_name": "test",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"ami": "bar"
},
"after_unknown": {
"id": true
}
}
}
],
"output_changes": {
"test": {
"actions": [
"create"
],
"before": null,
"after": "bar",
"after_unknown": false
}
},
"prior_state": {
"format_version": "0.1",
"terraform_version": "0.13.0",
"values": {
"outputs": {
"test": {
"sensitive": false,
"value": "bar"
}
},
"root_module": {
"resources": [
{
"address": "test_instance.test[0]",
"mode": "managed",
"type": "test_instance",
"name": "test",
"index": 0,
"provider_name": "test",
"schema_version": 0,
"values": {
"ami": "bar",
"id": "placeholder"
}
}
]
}
}
},
"configuration": {
"root_module": {
"outputs": {
"test": {
"expression": {
"references": [
"var.test_var"
]
}
}
},
"resources": [
{
"address": "test_instance.test",
"mode": "managed",
"type": "test_instance",
"name": "test",
"provider_config_key": "test",
"expressions": {
"ami": {
"references": [
"var.test_var"
]
}
},
"schema_version": 0,
"count_expression": {
"constant_value": 2
}
}
],
"variables": {
"test_var": {
"default": "bar"
}
}
}
}
}
24 changes: 24 additions & 0 deletions command/testdata/show-json/multi-resource-update/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": 4,
"terraform_version": "0.12.0",
"serial": 7,
"lineage": "configuredUnchanged",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "test_instance",
"name": "test",
"provider": "provider[\"registry.terraform.io/-/test\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"ami": "bar",
"id": "placeholder"
}
}
]
}
]
}

0 comments on commit a16a753

Please sign in to comment.