mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
json-output: Omit unchanged resource_drift entries
Previously, if any resources were found to have drifted, the JSON plan output would include a drift entry for every resource in state. This commit aligns the JSON plan output with the CLI UI, and only includes those resources where the old value does not equal the new value---i.e. drift has been detected. Also fixes a bug where the "address" field was missing from the drift output, and adds some test coverage.
This commit is contained in:
13
internal/command/testdata/show-json/drift/main.tf
vendored
Normal file
13
internal/command/testdata/show-json/drift/main.tf
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# In state with `ami = "foo"`, so this should be a regular update. The provider
|
||||
# should not detect changes on refresh.
|
||||
resource "test_instance" "no_refresh" {
|
||||
ami = "bar"
|
||||
}
|
||||
|
||||
# In state with `ami = "refresh-me"`, but the provider will return
|
||||
# `"refreshed"` after the refresh phase. The plan should show the drift
|
||||
# (`"refresh-me"` to `"refreshed"`) and plan the update (`"refreshed"` to
|
||||
# `"baz"`).
|
||||
resource "test_instance" "should_refresh" {
|
||||
ami = "baz"
|
||||
}
|
||||
174
internal/command/testdata/show-json/drift/output.json
vendored
Normal file
174
internal/command/testdata/show-json/drift/output.json
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
{
|
||||
"format_version": "0.2",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
{
|
||||
"address": "test_instance.no_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "no_refresh",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "bar",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
{
|
||||
"address": "test_instance.should_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "baz",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"resource_drift": [
|
||||
{
|
||||
"address": "test_instance.should_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "should_refresh",
|
||||
"change": {
|
||||
"actions": [
|
||||
"update"
|
||||
],
|
||||
"before": {
|
||||
"ami": "refresh-me",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "refreshed",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_sensitive": {},
|
||||
"before_sensitive": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"resource_changes": [
|
||||
{
|
||||
"address": "test_instance.no_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "no_refresh",
|
||||
"change": {
|
||||
"actions": [
|
||||
"update"
|
||||
],
|
||||
"before": {
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "bar",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_unknown": {},
|
||||
"after_sensitive": {},
|
||||
"before_sensitive": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"address": "test_instance.should_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "should_refresh",
|
||||
"change": {
|
||||
"actions": [
|
||||
"update"
|
||||
],
|
||||
"before": {
|
||||
"ami": "refreshed",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "baz",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_unknown": {},
|
||||
"after_sensitive": {},
|
||||
"before_sensitive": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"prior_state": {
|
||||
"format_version": "0.2",
|
||||
"values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
{
|
||||
"address": "test_instance.no_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "no_refresh",
|
||||
"schema_version": 0,
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"values": {
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
},
|
||||
{
|
||||
"address": "test_instance.should_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh",
|
||||
"schema_version": 0,
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"values": {
|
||||
"ami": "refreshed",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"configuration": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
{
|
||||
"address": "test_instance.no_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "no_refresh",
|
||||
"provider_config_key": "test",
|
||||
"schema_version": 0,
|
||||
"expressions": {
|
||||
"ami": {
|
||||
"constant_value": "bar"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"address": "test_instance.should_refresh",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh",
|
||||
"provider_config_key": "test",
|
||||
"schema_version": 0,
|
||||
"expressions": {
|
||||
"ami": {
|
||||
"constant_value": "baz"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
38
internal/command/testdata/show-json/drift/terraform.tfstate
vendored
Normal file
38
internal/command/testdata/show-json/drift/terraform.tfstate
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"version": 4,
|
||||
"terraform_version": "0.12.0",
|
||||
"serial": 7,
|
||||
"lineage": "configuredUnchanged",
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "no_refresh",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/test\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/test\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "refresh-me",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user