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

output_changes incorrectly calculated in the plan file #24628

Closed
marcinwyszynski opened this issue Apr 10, 2020 · 8 comments
Closed

output_changes incorrectly calculated in the plan file #24628

marcinwyszynski opened this issue Apr 10, 2020 · 8 comments
Labels

Comments

@marcinwyszynski
Copy link

marcinwyszynski commented Apr 10, 2020

Terraform Version

❯ terraform version
Terraform v0.12.24

Terraform Configuration Files

provider "random" {}

resource "random_id" "bacon" {
  keepers     = { bacon = "tasty" }
  byte_length = 16
}

output "bacon" { value = random_id.bacon.hex }

Steps to reproduce

After the change has been applied:

❯ terraform plan -out repro.plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

random_id.bacon: Refreshing state... [id=eprljZv58YrewNlMCchkQA]

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

❯ terraform plan -out repro.plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

random_id.bacon: Refreshing state... [id=eprljZv58YrewNlMCchkQA]

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

❯ terraform show -json repro.plan > repro.json
❯ cat repro.json | jq

{
  "format_version": "0.1",
  "terraform_version": "0.12.24",
  "planned_values": {
    "outputs": {
      "bacon": {
        "sensitive": false,
        "value": "7a9ae58d9bf9f18adec0d94c09c86440"
      }
    },
    "root_module": {
      "resources": [
        {
          "address": "random_id.bacon",
          "mode": "managed",
          "type": "random_id",
          "name": "bacon",
          "provider_name": "random",
          "schema_version": 0,
          "values": {
            "b64": "eprljZv58YrewNlMCchkQA",
            "b64_std": "eprljZv58YrewNlMCchkQA==",
            "b64_url": "eprljZv58YrewNlMCchkQA",
            "byte_length": 16,
            "dec": "162970085093216590396273492464954270784",
            "hex": "7a9ae58d9bf9f18adec0d94c09c86440",
            "id": "eprljZv58YrewNlMCchkQA",
            "keepers": { "bacon": "tasty" },
            "prefix": null
          }
        }
      ]
    }
  },
  "resource_changes": [
    {
      "address": "random_id.bacon",
      "mode": "managed",
      "type": "random_id",
      "name": "bacon",
      "provider_name": "random",
      "change": {
        "actions": ["no-op"],
        "before": {
          "b64": "eprljZv58YrewNlMCchkQA",
          "b64_std": "eprljZv58YrewNlMCchkQA==",
          "b64_url": "eprljZv58YrewNlMCchkQA",
          "byte_length": 16,
          "dec": "162970085093216590396273492464954270784",
          "hex": "7a9ae58d9bf9f18adec0d94c09c86440",
          "id": "eprljZv58YrewNlMCchkQA",
          "keepers": { "bacon": "tasty" },
          "prefix": null
        },
        "after": {
          "b64": "eprljZv58YrewNlMCchkQA",
          "b64_std": "eprljZv58YrewNlMCchkQA==",
          "b64_url": "eprljZv58YrewNlMCchkQA",
          "byte_length": 16,
          "dec": "162970085093216590396273492464954270784",
          "hex": "7a9ae58d9bf9f18adec0d94c09c86440",
          "id": "eprljZv58YrewNlMCchkQA",
          "keepers": { "bacon": "tasty" },
          "prefix": null
        },
        "after_unknown": {}
      }
    }
  ],
  "output_changes": {
    "bacon": {
      "actions": ["create"],
      "before": null,
      "after": "7a9ae58d9bf9f18adec0d94c09c86440",
      "after_unknown": false
    }
  },
  "prior_state": {
    "format_version": "0.1",
    "terraform_version": "0.12.24",
    "values": {
      "outputs": {
        "bacon": {
          "sensitive": false,
          "value": "7a9ae58d9bf9f18adec0d94c09c86440"
        }
      },
      "root_module": {
        "resources": [
          {
            "address": "random_id.bacon",
            "mode": "managed",
            "type": "random_id",
            "name": "bacon",
            "provider_name": "random",
            "schema_version": 0,
            "values": {
              "b64": "eprljZv58YrewNlMCchkQA",
              "b64_std": "eprljZv58YrewNlMCchkQA==",
              "b64_url": "eprljZv58YrewNlMCchkQA",
              "byte_length": 16,
              "dec": "162970085093216590396273492464954270784",
              "hex": "7a9ae58d9bf9f18adec0d94c09c86440",
              "id": "eprljZv58YrewNlMCchkQA",
              "keepers": { "bacon": "tasty" },
              "prefix": null
            }
          }
        ]
      }
    }
  },
  "configuration": {
    "provider_config": { "random": { "name": "random" } },
    "root_module": {
      "outputs": {
        "bacon": { "expression": { "references": ["random_id.bacon"] } }
      },
      "resources": [
        {
          "address": "random_id.bacon",
          "mode": "managed",
          "type": "random_id",
          "name": "bacon",
          "provider_config_key": "random",
          "expressions": {
            "byte_length": { "constant_value": 16 },
            "keepers": { "constant_value": { "bacon": "tasty" } }
          },
          "schema_version": 0
        }
      ]
    }
  }
}

Expected Behavior

The resulting JSON should set the value at $.output_changes.bacon.before to "7a9ae58d9bf9f18adec0d94c09c86440"
The resulting JSON should set the value at $.output_changes.bacon.actions to ["no-op"]

Actual Behavior

The resulting JSON sets the value at $.output_changes.bacon.before to null
The resulting JSON incorrectly sets the value at $.output_changes.bacon.actions to ["create"]

@danieldreier
Copy link
Contributor

Thanks for reporting this! If I'm reading this right, it looks like you're reporting an issue specific to the random provider rather than one with terraform core. I've labeled it, and it will get moved over to that provider's source repository by HashiBot shortly.

Please feel free to re-open this if I'm misunderstanding this and it is in fact a core issue.

@ghost
Copy link

ghost commented Apr 10, 2020

This issue has been automatically migrated to hashicorp/terraform-provider-random#110 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-random#110.

@ghost
Copy link

ghost commented May 11, 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 11, 2020
@kmoe
Copy link
Member

kmoe commented Oct 23, 2020

I believe this is a known Core issue, not an issue with the random provider. For all output_changes, no matter the provider, actions is always ["create"], no matter the value of the output in the state file.

It is documented that "In the Terraform CLI 0.12.0 release, Terraform is not yet fully able to track changes to output values, so the actions indicated may not be fully accurate, but the "after" value will always be correct."

@kmoe kmoe reopened this Oct 23, 2020
@ghost ghost closed this as completed Oct 23, 2020
@kmoe kmoe reopened this Oct 26, 2020
@ghost ghost closed this as completed Oct 26, 2020
@paddycarver paddycarver reopened this Oct 26, 2020
@skorfmann
Copy link

I believe this is a known Core issue, not an issue with the random provider. For all output_changes, no matter the provider, actions is always ["create"], no matter the value of the output in the state file.

Yes, I just reproduced this in https://github.com/hashicorp/terraform-cdk

@pselle
Copy link
Contributor

pselle commented Jan 13, 2021

@skorfmann I made a reproduction of this here, and wasn't able to reproduce on master https://github.com/danieldreier/terraform-issue-reproductions/tree/master/24628 nor on the v0.14 branch. Could you help with a reproduction?

@kmoe
Copy link
Member

kmoe commented May 4, 2021

I've tested https://github.com/danieldreier/terraform-issue-reproductions/tree/master/24628 with 0.12.29, 0.13.6, and 0.14.4. The former two versions show:

{
  "bacon": {
    "actions": [
      "create"
    ],
    "before": null,
    "after": "3eaf3393733ab75d0a1b567728508d62",
    "after_unknown": false
  }
}

and 0.14.4 shows:

{
  "bacon": {
    "actions": [
      "no-op"
    ],
    "before": "11f6a28096acfe941a034ed6460b1d02",
    "after": "11f6a28096acfe941a034ed6460b1d02",
    "after_unknown": false
  }
}

I therefore believe this bug was fixed somewhere between 0.13.6 and 0.14.4.

I'd still like someone from Core to comment on the documentation: "In the Terraform CLI 0.12.0 release, Terraform is not yet fully able to track changes to output values, so the actions indicated may not be fully accurate, but the "after" value will always be correct." Is this still true?

@crw crw added the bug label Aug 28, 2024
@crw
Copy link
Collaborator

crw commented Aug 28, 2024

I am going to close this issue due to age. Also, as @kmoe has subsequently joined the Core team, if the question still needed an answer presumably it can now be found. :)

@crw crw closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants