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

Resource addresses in prior state of a json plan lacking indexes #24110

Closed
mwhooker opened this issue Feb 13, 2020 · 2 comments · Fixed by #24256
Closed

Resource addresses in prior state of a json plan lacking indexes #24110

mwhooker opened this issue Feb 13, 2020 · 2 comments · Fixed by #24256
Assignees
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@mwhooker
Copy link
Contributor

mwhooker commented Feb 13, 2020

Terraform Version

0.12.20

Terraform Configuration Files

resource "null_resource" "cluster" {
  count = 3
}

Expected Behavior

I expect there to be symmetry between prior state and proposed state. The proposed state looks like

{
  "format_version": "0.1",
  "terraform_version": "0.12.20",
  "planned_values": {
    "root_module": {
      "resources": [
        {
          "address": "null_resource.cluster[0]",
          "mode": "managed",
          "type": "null_resource",
          "name": "cluster",
          "index": 0,
          "provider_name": "null",
          "schema_version": 0,
          "values": {
            "triggers": null
          }
        },
...

Actual Behavior

The prior state, if I delete the resources, looks like

  "prior_state": {
    "format_version": "0.1",
    "terraform_version": "0.12.20",
    "values": {
      "root_module": {
        "resources": [
          {
            "address": "null_resource.cluster",
            "mode": "managed",
            "type": "null_resource",
            "name": "cluster",
            "index": 0,
            "provider_name": "null",
            "schema_version": 0,
            "values": {
              "id": "7039102915404397285",
              "triggers": null
            }
          },
...

Steps to Reproduce

  1. Use example input
  2. terraform init
  3. terraform apply
  4. delete resource
  5. tf plan -out terraform.tfplan; tf show -json terraform.tfplan

Note that the resource addresses in the prior state do not contain an index.

@mildwonkey
Copy link
Contributor

A note for future @mildwonkey :

The address string is an addrs.Resource in state but an addrs.AbsResourceInstance in the planned changes.

@hashibot hashibot added bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases labels Feb 13, 2020
mildwonkey added a commit that referenced this issue Mar 3, 2020
Resource addresses in state output were not including index for
instances created with for_each or count, while the index was appearing
in the plan output. This PR fixes that inconsistency, adds tests, and
updates the existing tests.

Fixes #24110
mildwonkey added a commit that referenced this issue Mar 5, 2020
* command/jsonstate: fix inconsistency with resource address

Resource addresses in state output were not including index for
instances created with for_each or count, while the index was appearing
in the plan output. This PR fixes that inconsistency, adds tests, and
updates the existing tests.

Fixes #24110

* add tests showing expected prior state resource addressing
* added example of show json state output with modules
@ghost
Copy link

ghost commented Apr 5, 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 Apr 5, 2020
noahmercado pushed a commit to noahmercado/terraform that referenced this issue Apr 8, 2020
…#24256)

* command/jsonstate: fix inconsistency with resource address

Resource addresses in state output were not including index for
instances created with for_each or count, while the index was appearing
in the plan output. This PR fixes that inconsistency, adds tests, and
updates the existing tests.

Fixes hashicorp#24110

* add tests showing expected prior state resource addressing
* added example of show json state output with modules
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants