Skip to content

Commit 3ce9fdb

Browse files
Mark content in storage object content data source as computed (#12857) (#21074)
[upstream:326280da0ae9d98c47bfda24616d6da9555b9a6b] Signed-off-by: Modular Magician <[email protected]>
1 parent ebed29a commit 3ce9fdb

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

.changelog/12857.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
storage: fixed an issue where plans with a dependency on the `content` field in the `google_storage_bucket_object_content` data source could erroneously fail
3+
```

google/services/storage/data_source_storage_bucket_object_content.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func DataSourceGoogleStorageBucketObjectContent() *schema.Resource {
2020

2121
tpgresource.AddRequiredFieldsToSchema(dsSchema, "bucket")
2222
tpgresource.AddRequiredFieldsToSchema(dsSchema, "name")
23-
tpgresource.AddOptionalFieldsToSchema(dsSchema, "content")
23+
24+
// The field must be optional for backward compatibility.
25+
dsSchema["content"].Optional = true
2426

2527
return &schema.Resource{
2628
Read: dataSourceGoogleStorageBucketObjectContentRead,

google/services/storage/data_source_storage_bucket_object_content_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,59 @@ resource "google_storage_bucket" "contenttest" {
4949
force_destroy = true
5050
}`, content, bucket)
5151
}
52+
53+
func TestAccDataSourceStorageBucketObjectContent_Issue15717(t *testing.T) {
54+
55+
bucket := "tf-bucket-object-content-" + acctest.RandString(t, 10)
56+
content := "qwertyuioasdfghjk1234567!!@#$*"
57+
58+
config := fmt.Sprintf(`
59+
%s
60+
61+
output "output" {
62+
value = replace(data.google_storage_bucket_object_content.default.content, "q", "Q")
63+
}`, testAccDataSourceStorageBucketObjectContent_Basic(content, bucket))
64+
65+
acctest.VcrTest(t, resource.TestCase{
66+
PreCheck: func() { acctest.AccTestPreCheck(t) },
67+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
68+
Steps: []resource.TestStep{
69+
{
70+
Config: config,
71+
Check: resource.ComposeTestCheckFunc(
72+
resource.TestCheckResourceAttrSet("data.google_storage_bucket_object_content.default", "content"),
73+
resource.TestCheckResourceAttr("data.google_storage_bucket_object_content.default", "content", content),
74+
),
75+
},
76+
},
77+
})
78+
}
79+
80+
func TestAccDataSourceStorageBucketObjectContent_Issue15717BackwardCompatibility(t *testing.T) {
81+
82+
bucket := "tf-bucket-object-content-" + acctest.RandString(t, 10)
83+
content := "qwertyuioasdfghjk1234567!!@#$*"
84+
85+
config := fmt.Sprintf(`
86+
%s
87+
88+
data "google_storage_bucket_object_content" "new" {
89+
bucket = google_storage_bucket.contenttest.name
90+
content = "%s"
91+
name = google_storage_bucket_object.object.name
92+
}`, testAccDataSourceStorageBucketObjectContent_Basic(content, bucket), content)
93+
94+
acctest.VcrTest(t, resource.TestCase{
95+
PreCheck: func() { acctest.AccTestPreCheck(t) },
96+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
97+
Steps: []resource.TestStep{
98+
{
99+
Config: config,
100+
Check: resource.ComposeTestCheckFunc(
101+
resource.TestCheckResourceAttrSet("data.google_storage_bucket_object_content.new", "content"),
102+
resource.TestCheckResourceAttr("data.google_storage_bucket_object_content.new", "content", content),
103+
),
104+
},
105+
},
106+
})
107+
}

website/docs/d/storage_bucket_object_content.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ The following arguments are supported:
4141

4242
The following attributes are exported:
4343

44-
* `content` - (Computed) [Content-Language](https://tools.ietf.org/html/rfc7231#section-3.1.3.2) of the object content.
44+
* `content` - (Computed) The content of the object.

0 commit comments

Comments
 (0)