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

passing empty iterator to dynamic block doesn't destroy previously created resources #22787

Closed
shadjac opened this issue Sep 13, 2019 · 3 comments
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@shadjac
Copy link

shadjac commented Sep 13, 2019

Terraform Version

Terraform v0.12.7

Terraform Configuration Files

**.tfvars**

    secondary_sources = [
        {
        type                         = "BITBUCKET"
        source_identifier            = "common"
        location                     = "https://user@bitbucket.org/repo-name"
        buildspec                    = "config/default/buildspec.yml"
        }

    ]

**main.tf**


  dynamic "secondary_sources" {
    for_each = var.secondary_sources
        content {
            type               = secondary_sources.value.type
            source_identifier  = secondary_sources.value.source_identifier
            buildspec          = secondary_sources.value.buildspec
            location           = secondary_sources.value.location
            }
    }

**variables.tf**

variable "secondary_sources" {
  type = list(object({
    type                 = string
    source_identifier    = string
    location             = string
    buildspec            = string
    
  }))
}

Debug Output

Crash Output

Expected Behavior

Actual Behavior

When

secondary_sources = [
        {
        type                         = "BITBUCKET"
        source_identifier            = "common"
        location                     = "https://user@bitbucket.org/repo-name"
        buildspec                    = "config/default/buildspec.yml"
        }
    ]

terraform plan output

      + secondary_sources {
          + buildspec         = "config/default/buildspec.yml"
          + location          = "https://user@bitbucket.org/repo-name"
          + source_identifier = "common"
          + type              = "BITBUCKET"
        }

Plan: 0 to add, 1 to change, 0 to destroy.

When secondary_sources array is not empty, it adds the secondary source to code build.
If I want to remove the secondary source, I pass empty array to variable secondary_sources

terraform plan output when secondary_sources=[]

- secondary_sources {
          - buildspec           = "config/default/buildspec.yml" -> null
          - git_clone_depth     = 0 -> null
          - insecure_ssl        = false -> null
          - location            = "https://user@bitbucket.org/repo-name" -> null
          - report_build_status = false -> null
          - source_identifier   = "common" -> null
          - type                = "BITBUCKET" -> null
        }
aws_codebuild_project.code_build_project: Modifying... [id=arn:aws:codebuild:<resource-name>]
aws_codebuild_project.code_build_project: Modifications complete after 1s [id=arn:aws:codebuild:<resource-name>]

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

But, This is misleading output. I can still see the secondary source on code build.

The state file looks like this -

"secondary_sources": [],

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. Provide secondary_sources with one element in the list.
  2. terraform apply
  3. Now, change the value of secondary_sources to [] empty array.
  4. terraform apply
  5. check whether code build secondary source is removed.

Additional Context

References

@mildwonkey
Copy link
Contributor

Hi @shadjac!
Without more information, it's hard to tell if this is a provider resource specific issue or not. Can you please share the full configuration of this resource, and also fill in the rest of the information requested by the template (including your debug log)? Thank you.

@mildwonkey mildwonkey added the waiting-response An issue/pull request is waiting for a response from the community label Sep 13, 2019
@hashibot hashibot added bug config v0.12 Issues (primarily bugs) reported against v0.12 releases labels Sep 17, 2019
@hashibot
Copy link
Contributor

hashibot commented Oct 7, 2019

Hello again!

We didn't hear back from you, so I'm going to close this in the hope that a previous response gave you the information you needed. If not, please do feel free to re-open this and leave another comment with the information my human friends requested above. Thanks!

@hashibot hashibot closed this as completed Oct 7, 2019
@ghost
Copy link

ghost commented Nov 7, 2019

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.

@hashicorp hashicorp locked and limited conversation to collaborators Nov 7, 2019
@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

3 participants