Skip to content

Commit bafef4b

Browse files
wafrelkaPerlMonker303
authored andcommitted
Mark content in storage object content data source as computed (GoogleCloudPlatform#12857)
1 parent 79b7d7c commit bafef4b

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

mmv1/third_party/terraform/services/storage/data_source_storage_bucket_object_content.go

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

1919
tpgresource.AddRequiredFieldsToSchema(dsSchema, "bucket")
2020
tpgresource.AddRequiredFieldsToSchema(dsSchema, "name")
21-
tpgresource.AddOptionalFieldsToSchema(dsSchema, "content")
21+
22+
// The field must be optional for backward compatibility.
23+
dsSchema["content"].Optional = true
2224

2325
return &schema.Resource{
2426
Read: dataSourceGoogleStorageBucketObjectContentRead,

mmv1/third_party/terraform/services/storage/data_source_storage_bucket_object_content_test.go

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

mmv1/third_party/terraform/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)