Skip to content

Instantly share code, notes, and snippets.

@kuzuha
Last active November 24, 2017 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuzuha/c46f52573759eb9d1262f7505a00ff9c to your computer and use it in GitHub Desktop.
Save kuzuha/c46f52573759eb9d1262f7505a00ff9c to your computer and use it in GitHub Desktop.

WHAT HAPPEND

provder configuration interpolation behavior seems changed since terraform 0.11.0.

before 0.11.0, values that from data resource variable in provider configuration came from terraform.state.
AFTER apply, values in terraform.state will be changed.
new values will be used when NEXT plan.

after 0.11.0, values that from data resource variable in provider configuration came from themselves.
new values are used IMMEDIATELY.

QUESTION

this change seems to be undocummented.
is this intentional?

MY OPINION

the new behavior is preferred.
becouse, user must change and apply .tf BEFORE configuration(e.g. mysql user password) is REALLY changed.
if user changed configuration BEFORE apply .tf, there is no normally recovery method.

I'm planning to develop custom provider plugin depends this change.

variable "db" {}
variable "port" {}
provider "mysql" {
endpoint = "${data.null_data_source.mysql.inputs["host"]}:${data.null_data_source.mysql.inputs["port"]}"
username = "root"
password = ""
}
data "null_data_source" "mysql" {
inputs = {
host = "localhost"
port = "${var.port}"
}
}
resource "mysql_database" "db" {
name = "${var.db}"
}
#!/bin/sh
mysql -u root -e 'drop database if exists db_0_10_8; drop database if exists db_0_11_0;'
rm -rf 0.10.8 0.11.0
mkdir 0.10.8 0.11.0
cp main.tf 0.10.8/main.tf
cp main.tf 0.11.0/main.tf
cd 0.10.8
cp ../main.tf .
wget https://releases.hashicorp.com/terraform/0.10.8/terraform_0.10.8_darwin_amd64.zip
# or linux
# wget https://releases.hashicorp.com/terraform/0.10.8/terraform_0.10.8_linux_amd64.zip
unzip terraform_0.10.8_darwin_amd64.zip
./terraform init
# connect to valid port.
# it will success.
./terraform apply -var 'port=3306' -var 'db=db_0_10_8'
# connect to invalid port.
# however it will success.
./terraform destroy -force -var 'port=3307' -var 'db=db_0_10_8'
cd ..
cd 0.11.0
wget https://releases.hashicorp.com/terraform/0.11.0/terraform_0.11.0_darwin_amd64.zip
# or linux
# wget https://releases.hashicorp.com/terraform/0.11.0/terraform_0.11.0_linux_amd64.zip
unzip terraform_0.11.0_darwin_amd64.zip
./terraform init
# connect to valid port.
# it will success.
./terraform apply -auto-approve -var 'port=3306' -var 'db=db_0_11_0'
# connect to invalid port.
# it will fail.
./terraform destroy -force -var 'port=3307' -var 'db=db_0_11_0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment