terraform-provider-google: google_storage_bucket resources with inconsistent final plan against dynamic labels in version 4.40.0

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

tested in both v1.2.8 and v1.3.2, on linux_amd64

Affected Resource(s)

  • google_storage_bucket

Terraform Configuration Files

terraform {
    required_version = "~>1.0"
    backend "local" {
        path = "/my/local/machine/path/terraform.tfstate"
    }
    required_providers {
        null = {
            version = "~>3.0"
        }
        random = {
            version = "~>3.0"
        }
        google = {
            // using an older version (e.g. 4.39.0) would work before
            version = "4.40.0"
        }
    }
}

resource "random_string" "this" {
    length = 3
    upper   = false
    numeric = false
    special = false
}

resource "null_resource" "this" {}

resource "google_storage_bucket" "bucket" {
  project      =  "my-google-project"
  name          = "onion-super-bucket"
  location      = "EU"
  force_destroy = true
  labels = {
    // either one of these is enough for it to fail
    "one" = "${null_resource.this.id}"
    "two" = "${random_string.this.result}"
  }
}

Debug Output

β•·
β”‚ Error: Provider produced inconsistent final plan
β”‚
β”‚ When expanding the plan for google_storage_bucket.bucket to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/google" produced an invalid new value for .labels: was null, but now cty.MapVal(map[string]cty.Value{"one":cty.StringVal("4696786782519982561"), "two":cty.StringVal("fud")}).
β”‚
β”‚ This is a bug in the provider, which should be reported in the provider's own issue tracker.
β•΅

Panic Output

Expected Behavior

terraform apply will succeed in one-go

Actual Behavior

terraform apply failed with the error above. Re-running terraform apply however would work.

Steps to Reproduce

  1. create a module and copy the code into a new file called main.tf.
  2. Change the backend path and update the project name inside google_storage_bucket
  3. terraform apply

Important Factoids

References

  • b/275608065

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 20

Most upvoted comments

I think it is not the merge nor the formatdate, it is the use of timestamp() itself. Even in the docs they advice against using timestamp() on a resource:

The result of this function will change every second, so using this function directly with resource attributes will cause a diff to be detected on every Terraform run. We do not recommend using this function in resource attributes, but in rare cases it can be used in conjunction with the ignore_changes lifecycle meta-argument to take the timestamp only on initial creation of the resource. For more stable time handling, see the Time Provider.

Other issue i found:

https://github.com/hashicorp/terraform/issues/22461

But i do not know why Terraform fails so hard in this case.

Can someone please try the provider in version 4.66.0 or newer and check if the issue is fixed?

https://github.com/hashicorp/terraform-provider-google/releases/tag/v4.66.0

Hello, are there any updates regarding this issue ? Thanks !

hi all,

as I am the initial contributor of this suppress func:

Seems for me like a terraform sdk bug itself, not a provider issue.

var and / or local references work fine, while β€œonly” resource outputs seem to fail:

variable "foo" { 
    type = string
    default = "bar"  
}

locals {
    foo = "bar"
}

resource "google_storage_bucket" "bucket" {
  project      =  "project"
  name          = "bucket"
  location      = "EU"
  force_destroy = true
  labels = {
    "three" = "foo"
    "two"   = "${var.foo}"
    "one"   = "${local.foo}"
  }
}