Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform breaks when values removed from config for at least Set and Bool (but not String) #952

Closed
jefferai opened this issue Feb 8, 2015 · 2 comments · Fixed by #984 or #986
Closed
Assignees

Comments

@jefferai
Copy link
Member

jefferai commented Feb 8, 2015

May be related to #950 .

Given the following provider configuration:

resource "docker_container" "example" {
    name = "example"
    image = "ubuntu:14.04"
    hostname = "example"
    dns = ["1.2.3.4", "5.6.7.8"]
    publish_all_ports = true
}

I can apply the configuration and get an expected result:

docker_container.example: Creating...
  active:                     "" => "<computed>"
  computed_dns.#:             "" => "<computed>"
  computed_domainname:        "" => "<computed>"
  computed_env.#:             "" => "<computed>"
  computed_hostname:          "" => "<computed>"
  computed_image:             "" => "<computed>"
  computed_publish_all_ports: "" => "<computed>"
  dns.#:                      "" => "2"
  dns.909960769:              "" => "5.6.7.8"
  dns.961314917:              "" => "1.2.3.4"
  hostname:                   "" => "example"
  image:                      "" => "ubuntu:14.04"
  name:                       "" => "example"
  publish_all_ports:          "" => "1"
docker_container.example: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

So far so good, but here's where things go south. If I remove several values from configuration:

resource "docker_container" "example" {
    name = "example"
    image = "ubuntu:14.04"
    #hostname = "example"
    #dns = ["1.2.3.4", "5.6.7.8"]
    #publish_all_ports = true
}

Upon the first apply, I see what is expected:

docker_container.example: Refreshing state... (ID: 56f18bdffc0af6dda8fa76970718444db3be006ae18e67e7688c6193a450e035)
docker_container.example: Modifying...
  dns.#:             "2" => "0"
  hostname:          "example" => ""
  publish_all_ports: "1" => ""
docker_container.example: Modifications complete

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

But if I immediately do a terraform apply again, I see:

docker_container.example: Refreshing state... (ID: d7e9215bcfd58d923357419c9ac3fd53d922e4853f703d2695760e88e800c7fa)
docker_container.example: Modifying...
  dns.#:             "2" => "0"
  publish_all_ports: "0" => ""
docker_container.example: Modifications complete

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Uh oh. This happens every time I apply. Let's look at the tfstate file:

{
    "version": 1,
    "serial": 3,
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {
                "docker_container.example": {
                    "type": "docker_container",
                    "primary": {
                        "id": "7d80bb962fefbd82e595612137789bc8bee303f1b23fa5a3da600eb9afeff696",
                        "attributes": {
                            "active": "false",
                            "computed_dns.#": "2",
                            "computed_dns.909960769": "5.6.7.8",
                            "computed_dns.961314917": "1.2.3.4",
                            "computed_domainname": "",
                            "computed_env.#": "2",
                            "computed_env.1450990614": "HOME=/",
                            "computed_env.1827816": "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                            "computed_hostname": "7d80bb962fef",
                            "computed_image": "c4ff7513909dedf4ddf3a450aea68cd817c42e698ebccf54755973576525c416",
                            "computed_publish_all_ports": "false",
                            "dns.#": "2",
                            "dns.909960769": "5.6.7.8",
                            "dns.961314917": "1.2.3.4",
                            "hostname": "",
                            "id": "7d80bb962fefbd82e595612137789bc8bee303f1b23fa5a3da600eb9afeff696",
                            "image": "ubuntu:14.04",
                            "name": "example",
                            "publish_all_ports": "false"
                        }
                    }
                }
            }
        }
    ]
}

Note that dns.# does still show 2, and both entries are there. The removal is being noticed every time I hit apply, and Terraform is performing a change, but it's not actually recording that change.

publish_all_ports may in fact be a different bug; note that it's being stored as a string in the tfstate file, and the output during running suggests that it's taking a representation of the bool as an integer value stored in a string ("0") and moving it to the empty string...IOW, the default value for a string type.

It is also worth noting that the string value I commented out does not experience this problem; only the set and bool types. I haven't tried a map or integer but I wouldn't be surprised if they have similar problems as I think the issues are stemming from all values being converted to strings in the tfstate file.

Of course, there is an argument that those values should be removed entirely from the tfstate file as a fix to #950 .

This is based off of current master (05078bc).

@mitchellh
Copy link
Contributor

Fixed by above two PRs, will close once merged.

@ghost
Copy link

ghost commented May 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants