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

Cannot read the content attribute of the google_storage_bucket_object_content data source #15717

Closed
Assignees
Labels

Comments

@wafrelka
Copy link

wafrelka commented Sep 5, 2023

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

$ terraform -v
Terraform v1.5.6
on darwin_arm64
+ provider registry.terraform.io/hashicorp/google v4.80.0
+ provider registry.terraform.io/hashicorp/time v0.9.1

Affected Resource(s)

  • google_storage_bucket_object_content

Terraform Configuration Files

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.80.0"
    }
    time = {
      source  = "hashicorp/time"
      version = "0.9.1"
    }
  }
}

resource "time_sleep" "foo" {
  create_duration = "1s"
}

data "google_storage_bucket_object_content" "landsat" {
  bucket     = "gcp-public-data-landsat"
  name       = "LC08/01/001/003/LC08_L1GT_001003_20171007_20171023_01_T2/LC08_L1GT_001003_20171007_20171023_01_T2_ANG.txt"
  depends_on = [time_sleep.foo]
}

output "output" {
  value = replace(data.google_storage_bucket_object_content.landsat.content, "END", "end")
}

Debug Output

Expected Behavior

terraform apply succeeds.

Actual Behavior

terraform apply failed with the following error.

Error: Invalid function argument

  on main.tf line 25, in output "output":
  25:   value = replace(data.google_storage_bucket_object_content.landsat.content, "END", "end")
    ├────────────────
    │ while calling replace(str, substr, replace)
    │ data.google_storage_bucket_object_content.landsat.content is null

Invalid value for "str" parameter: argument must not be null.

Removing the depends_on attribute resolves the error.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

similar reports

root causes

The document says content is a computed attribute, but the implementation appears to disagree.
I suspect this is the root cause of this problem.

(The document also says it is "Content-Language of the object content", but this also appears to be wrong.)

tpgresource.AddOptionalFieldsToSchema(dsSchema, "content")

func AddOptionalFieldsToSchema(schema map[string]*schema.Schema, keys ...string) {
FixDatasourceSchemaFlags(schema, false, keys...)
}

func FixDatasourceSchemaFlags(schema map[string]*schema.Schema, required bool, keys ...string) {
for _, v := range keys {
schema[v].Computed = false
schema[v].Optional = !required
schema[v].Required = required
}
}

@wafrelka wafrelka added the bug label Sep 5, 2023
@edwardmedia edwardmedia self-assigned this Sep 5, 2023
@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 5, 2023

@wafrelka noticed below statement. Curious why you want to add depends_on?

Removing the depends_on attribute resolves the error.

Mind sharing your debug logs for both working and not working applies?

@wafrelka
Copy link
Author

wafrelka commented Sep 5, 2023

I added depends_on to make it easy to reproduce.

Actually I encountered this problem while writing terraform config where a google_storage_bucket_object_content data source implicitly depends on a google_storage_bucket resource through the bucket attribute, like the example described in #14666. When the dependency google_storage_bucket needs to be updated, the content attribute becomes null in the plan phase.

debug log: https://gist.github.com/wafrelka/8a192df15855911533940f2a384bc730

@wafrelka
Copy link
Author

still reproducible on v4.83.0

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.