Terraform: panic: value is marked, so must be unmarked first - for loop in output

Created on 28 Dec 2020  路  4Comments  路  Source: hashicorp/terraform

Terraform Version

Terraform v0.14.3

Terraform Configuration Files

output "master_nodes" {
  value = {
    for i in range(length(hcloud_server.control_planes)) :
    hcloud_server.control_planes[i].name => {
      name = hcloud_server.control_planes[i].name
      ip = hcloud_server_network.control_planes[i].ip
      connection = {
        host = hcloud_server.control_planes[i].ipv4_address
      }
    }
  }
  sensitive = true
}

Debug Output


https://gist.github.com/iamalirezaj/6886a2805f82b09078777e2658fc3805

Crash Output


https://gist.github.com/iamalirezaj/6886a2805f82b09078777e2658fc3805

Expected Behavior


Command succeeded

Actual Behavior


panic: value is marked, so must be unmarked first

Steps to Reproduce

  • terraform init
  • terraform apply
  • Additional Context


    Im using a for loop to create an object of multiple servers in an output!

    References

    • #27107
    bug confirmed new v0.14

    Most helpful comment

    @iamalirezaj I'm not sure why you think this output with a for loop is the source of the problem here, but the crash log you supplied doesn't agree with that. Instead, the issue appears to be using variable validation in a module input variable which is bound to a sensitive value.

    Reproduction case below, panics with terraform plan:

    main.tf

    variable "bar" {
      default = "nah"
      sensitive = true
    }
    
    module "foo" {
      source = "./foo"
      test = var.bar
    }
    

    foo/main.tf:

    variable "test" {
      type = string
    
      validation {
        condition     = var.test != "nope"
        error_message = "Value must not be \"nope\"."
      }
    }
    

    All 4 comments

    Same error with a for_each loop too.

    Hi! Thank you for reporting this! Based on your errors, I believe that this is probably a valid issue, and in order to hand it off to engineers to be fixed I need to reproduce it locally.

    To do that, I have to be able to run this and run it on my workstation without inventing any details in order to be confident we're seeing the same behavior. As-is, the example case you provided has a bunch of variables that I don't have the data for. It would be super helpful if you could replace those with static data or declare variables so I don't have to invent fake data to reproduce your crash case.

    @clement-pruvot the same goes for you - you may, or may not be seeing the same underlying bug, and so if you can come up with a simple reproduction case, we can confirm whether the fix we make for the parent issue also fixes the issue you're seeing.

    Can you both please restate your reproduction cases such that I can copy-paste it and run it locally? If you need to use providers, this would ideally use the null resource provider rather than a real provider in order to minimize external dependencies.

    @iamalirezaj I'm not sure why you think this output with a for loop is the source of the problem here, but the crash log you supplied doesn't agree with that. Instead, the issue appears to be using variable validation in a module input variable which is bound to a sensitive value.

    Reproduction case below, panics with terraform plan:

    main.tf

    variable "bar" {
      default = "nah"
      sensitive = true
    }
    
    module "foo" {
      source = "./foo"
      test = var.bar
    }
    

    foo/main.tf:

    variable "test" {
      type = string
    
      validation {
        condition     = var.test != "nope"
        error_message = "Value must not be \"nope\"."
      }
    }
    

    @alisdair Yeah, i was trying to explain what i was doing when i got this error.
    as you can see, i was using hetzner cloud provider and it was a little bit difficult for me to debug the code to see what was actually happen!
    Thanks for checking this out

    Was this page helpful?
    0 / 5 - 0 ratings