-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Unexpected behaviour with google_storage_bucket_object. Cannot access content
of the file even though it shows up in state and output
#14666
Comments
@periwinkleFTW using your code, I am receiving below content of a object.
Do you want to share your debug log so I can take a closer look? |
@edwardmedia Try using the content as an input in another resource. For example I want to use it to download the yaml file with api definition to deploy API gateway (I wish i could point google_api_gateway_api_config to the bucket directly, but oh well). This is the yaml file I am using:
When I run these resources:
I get an error even if you try to interpolate it. I am so confused but I do not see any other way I can deploy API gateway with the yaml file stored in a bucket =( |
If there is another way to deploy an API gateway using a yaml file stored in a bucket that works with Terraform Cloud and does not rely on google_storage_bucket_object_content I would be on cloud9 . Could it be a problem with my yaml file? |
I tried it with your yaml: and the same behaviour. Also same behaviour with
terraform -v
Is there a way to the get the contents of a file using data.google_storage_object? tf resoures: data "google_storage_bucket_object_content" "api_config_yaml_object_content" {
depends_on = [module.api_config_generator]
bucket = module.storage.api_config_bucket.name
name = "configs/test1.yaml"
}
output "object" {
value = data.google_storage_bucket_object_content.api_config_yaml_object_content
}
output "object_contents" {
value = data.google_storage_bucket_object_content.api_config_yaml_object_content.content
}
output "object_bucket" {
value = data.google_storage_bucket_object_content.api_config_yaml_object_content.bucket
}
output "object_id" {
value = data.google_storage_bucket_object_content.api_config_yaml_object_content.id
} Terraform plan and apply: # data.google_storage_bucket_object_content.api_config_yaml_object_content will be read during apply
# (depends on a resource or a module with changes pending)
<= data "google_storage_bucket_object_content" "api_config_yaml_object_content" {
+ bucket = "andrey-dev-api-config-files-25a3"
+ cache_control = (known after apply)
+ content_disposition = (known after apply)
+ content_encoding = (known after apply)
+ content_language = (known after apply)
+ content_type = (known after apply)
+ crc32c = (known after apply)
+ customer_encryption = (known after apply)
+ detect_md5hash = (known after apply)
+ event_based_hold = (known after apply)
+ id = (known after apply)
+ kms_key_name = (known after apply)
+ md5hash = (known after apply)
+ media_link = (known after apply)
+ metadata = (known after apply)
+ name = "configs/test1.yaml"
+ output_name = (known after apply)
+ self_link = (known after apply)
+ source = (known after apply)
+ storage_class = (known after apply)
+ temporary_hold = (known after apply)
}
Plan: 2 to add, 1 to change, 1 to destroy.
Changes to Outputs:
~ object = {
+ cache_control = (known after apply)
~ content = <<-EOT
#Comment: This is a supermarket list using YAML
#Note that - character represents the list
---
food:
- vegetables: tomatoes #first list item
- fruits: #second list item
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
EOT -> null
+ content_disposition = (known after apply)
+ content_encoding = (known after apply)
+ content_language = (known after apply)
+ content_type = (known after apply)
+ crc32c = (known after apply)
+ customer_encryption = (known after apply)
+ detect_md5hash = (known after apply)
+ event_based_hold = (known after apply)
~ id = "andrey-dev-api-config-files-25a3-configs/test1.yaml" -> (known after apply)
+ kms_key_name = (known after apply)
+ md5hash = (known after apply)
+ media_link = (known after apply)
+ metadata = (known after apply)
name = "configs/test1.yaml"
+ output_name = (known after apply)
+ self_link = (known after apply)
+ source = (known after apply)
+ storage_class = (known after apply)
+ temporary_hold = (known after apply)
# (1 unchanged attribute hidden)
}
+ object_bucket = "andrey-dev-api-config-files-25a3"
+ object_id = (known after apply)
module.api_config_generator.google_storage_bucket_object.params_py_file: Destroying... [id=andrey-dev-api-params-25a3-params/params.py]
module.firebase.google_identity_platform_project_default_config.firebase_auth: Modifying... [id=andrey-dev-project-25a3]
module.api_config_generator.google_storage_bucket_object.params_py_file: Destruction complete after 0s
module.api_config_generator.local_file.params: Creating...
module.api_config_generator.local_file.params: Creation complete after 0s [id=9b0b46a92f85438e54680a80c027d1a391e810ab]
module.api_config_generator.google_storage_bucket_object.params_py_file: Creating...
module.firebase.google_identity_platform_project_default_config.firebase_auth: Modifications complete after 0s [id=andrey-dev-project-25a3]
module.api_config_generator.google_storage_bucket_object.params_py_file: Creation complete after 1s [id=andrey-dev-api-params-25a3-params/params.py]
data.google_storage_bucket_object_content.api_config_yaml_object_content: Refreshing...
data.google_storage_bucket_object_content.api_config_yaml_object_content: Refresh complete after 0s [id=andrey-dev-api-config-files-25a3-configs/test1.yaml]
Apply complete! Resources: 2 added, 1 changed, 1 destroyed.
Outputs:
object_id = "andrey-dev-api-config-files-25a3-configs/test1.yaml"
object = {
bucket = "andrey-dev-api-config-files-25a3"
content = <<-EOT
#Comment: This is a supermarket list using YAML
#Note that - character represents the list
---
food:
- vegetables: tomatoes #first list item
- fruits: #second list item
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
EOT
id = "andrey-dev-api-config-files-25a3-configs/test1.yaml"
name = "configs/test1.yaml"
}
object_bucket = "andrey-dev-api-config-files-25a3" I hope that helps |
@periwinkleFTW using below config, I see foo.bar is successfully created and its content is the same as sample.yaml. data "google_storage_bucket_object_content" "my_file" {
bucket = "issue14666"
name = "sample.yaml"
}
resource "local_file" "test_file" {
content = data.google_storage_bucket_object_content.my_file.content
# content = "foo"
filename = "${path.module}/foo.bar"
} Not sure what the problem was with you |
@edwardmedia |
@periwinkleFTW Glad I can hep. Yes, keep us updated. |
@edwardmedia Everything works as expected if I run storage_object and local_file from root. It does not show content if those resources are inside the module. No idea why, but I will keep it as is. I have another issue with google_api_gateway_api_config. I relies on the dynamically generated yaml file, the problem is that using this dynamically generated variable with interpolation in │ Error: Provider produced inconsistent final plan
│
│ When expanding the plan for local_file.local_api_config_file to include new
│ values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/local" produced an invalid new value for
│ .content: was cty.StringVal("dummy_string"), but now
│ cty.StringVal("basePath: /\ndefinitions:\n accountsCmAccount:\n
│ properties:\n account_id:\n type: integer\n
...
│
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
Operation failed: failed running terraform apply (exit 1) Here are the resources:
Depends_on does not seem to work either =( API gateway will be the death of me |
@periwinkleFTW the resource appears working as expected. You may reach out to the Terraform to see if they can help on module stuff. Closing this issue now. |
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. |
Community Note
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 tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
google_storage_bucket_object
local_file
google_*
Terraform Configuration Files
Debug Output
Changes to Outputs:
}
~ object_id = "api-config-files-3ccf-configs/spending-api.yaml" -> (known after apply)
Panic Output
Expected Behavior
I expect terraform to be able to interpolate the data obtained from the specified object.
Using the
output
withgoogle_storage_bucket_object
or inspecting state of this object (terraform state show google_storage_bucket_object.my_object) show that resource has 4 attributes (bucket, content, id, name).Actual Behavior
Trying to access the
content
of the google_storage_bucket_object returns null, however other attributes like bucket, name, and id are accessible. Running output on the whole object shows content is there.Steps to Reproduce
terraform apply
Important Factoids
The issue could be due to multiline nature of yaml files. Same behaviour with json
Configuration uses Terraform Cloud.
Deployed both from intel macos, does not work
Deployed from m1 macos, it worked once but then content was null afterwards
References
https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/storage_bucket_object_content
The text was updated successfully, but these errors were encountered: