mirror of https://github.com/hashicorp/terraform
Configuration-driven moves are represented in the plan file by setting the resource's `PrevRunAddr` to a different value than its `Addr`. For JSON plan output, we here add a new field to resource changes, `previous_address`, which is present and non-empty only if the resource is planned to be moved. Like the CLI UI, refresh-only plans will include move-only changes in the resource drift JSON output. In normal plan mode, these are elided to avoid redundancy with planned changes.pull/29603/head
parent
78705f4f10
commit
78c4a8c461
@ -0,0 +1,22 @@
|
||||
# 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_with_move" {
|
||||
ami = "baz"
|
||||
}
|
||||
|
||||
terraform {
|
||||
experiments = [ config_driven_move ]
|
||||
}
|
||||
|
||||
moved {
|
||||
from = test_instance.should_refresh
|
||||
to = test_instance.should_refresh_with_move
|
||||
}
|
||||
@ -0,0 +1,177 @@
|
||||
{
|
||||
"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_with_move",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh_with_move",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "baz",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"resource_drift": [
|
||||
{
|
||||
"address": "test_instance.should_refresh_with_move",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"previous_address": "test_instance.should_refresh",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "should_refresh_with_move",
|
||||
"change": {
|
||||
"actions": [
|
||||
"update"
|
||||
],
|
||||
"before": {
|
||||
"ami": "refresh-me",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "refreshed",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_sensitive": {},
|
||||
"after_unknown": {},
|
||||
"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_with_move",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"previous_address": "test_instance.should_refresh",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "should_refresh_with_move",
|
||||
"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_with_move",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh_with_move",
|
||||
"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_with_move",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "should_refresh_with_move",
|
||||
"provider_config_key": "test",
|
||||
"schema_version": 0,
|
||||
"expressions": {
|
||||
"ami": {
|
||||
"constant_value": "baz"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
resource "test_instance" "baz" {
|
||||
ami = "baz"
|
||||
}
|
||||
|
||||
terraform {
|
||||
experiments = [ config_driven_move ]
|
||||
}
|
||||
|
||||
moved {
|
||||
from = test_instance.foo
|
||||
to = test_instance.baz
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
{
|
||||
"format_version": "0.2",
|
||||
"planned_values": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
{
|
||||
"address": "test_instance.baz",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "baz",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "baz",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"resource_changes": [
|
||||
{
|
||||
"address": "test_instance.baz",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"previous_address": "test_instance.foo",
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"name": "baz",
|
||||
"change": {
|
||||
"actions": [
|
||||
"update"
|
||||
],
|
||||
"before": {
|
||||
"ami": "foo",
|
||||
"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.baz",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "baz",
|
||||
"schema_version": 0,
|
||||
"provider_name": "registry.terraform.io/hashicorp/test",
|
||||
"values": {
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
},
|
||||
"sensitive_values": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"configuration": {
|
||||
"root_module": {
|
||||
"resources": [
|
||||
{
|
||||
"address": "test_instance.baz",
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "baz",
|
||||
"provider_config_key": "test",
|
||||
"schema_version": 0,
|
||||
"expressions": {
|
||||
"ami": {
|
||||
"constant_value": "baz"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": 4,
|
||||
"terraform_version": "0.12.0",
|
||||
"serial": 7,
|
||||
"lineage": "configuredUnchanged",
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "test_instance",
|
||||
"name": "foo",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/test\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in new issue