This almost empty provider has been created to test a Terraform bug.
go build
terraform init
terrafom planIt seems that default value (or Default or DefaultFunc) is applied for string fields (at least)
when we provide an empty string but only when there's no existing state.
With the following main.tf file:
resource "fake" "test" {
value = ""
}Starting from scratch (with no state):
$ terraform plan
Terraform will perform the following actions:
# fake.test will be created
+ resource "fake" "test" {
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
value = "plop"
}
Updating main.tf with:
resource "fake" "test" {
value = "tmp"
}Then:
$ terraform plan
Terraform will perform the following actions:
# fake.test will be updated in-place
~ resource "fake" "test" {
id = "toto"
~ value = "plop" -> "tmp"
}
Plan: 0 to add, 1 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
value = "tmp"
}Reverting main.tf to:
resource "fake" "test" {
value = ""
}Then:
$ terraform plan
Terraform will perform the following actions:
# fake.test will be updated in-place
~ resource "fake" "test" {
id = "toto"
- value = "tmp" -> null
}
Plan: 0 to add, 1 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
}resource "fake" "test" {
value = null
}$ terraform plan
Terraform will perform the following actions:
# fake.test will be created
+ resource "fake" "test" {
+ id = (known after apply)
+ value = "plop"
}
Plan: 1 to add, 0 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
value = "plop"
}resource "fake" "test" {
value = "tmp"
}$ terraform plan
Terraform will perform the following actions:
# fake.test will be updated in-place
~ resource "fake" "test" {
id = "toto"
~ value = "plop" -> "tmp"
}
Plan: 0 to add, 1 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
value = "tmp"
}resource "fake" "test" {
value = null
}$ terraform plan
Terraform will perform the following actions:
# fake.test will be updated in-place
~ resource "fake" "test" {
id = "toto"
~ value = "tmp" -> "plop"
}
Plan: 0 to add, 1 to change, 0 to destroy.
$ terraform apply -auto-approve
[...]
$ terraform state show fake.test
# fake.test:
resource "fake" "test" {
id = "toto"
value = "plop"
}resource "fake" "test" {
value = ""
}
$ terraform011 apply -auto-approve
[...]
$ terraform011 state show fake.test
id = toto