@@ -1301,3 +1301,65 @@ resource "google_pubsub_topic" "topic" {
13011301}
13021302` , context )
13031303}
1304+
1305+ func TestAccCGCSnippet_storageStaticWebsiteExample (t * testing.T ) {
1306+ t .Parallel ()
1307+
1308+ context := map [string ]interface {}{
1309+ "random_suffix" : randString (t , 10 ),
1310+ }
1311+
1312+ vcrTest (t , resource.TestCase {
1313+ PreCheck : func () { testAccPreCheck (t ) },
1314+ Providers : testAccProviders ,
1315+ Steps : []resource.TestStep {
1316+ {
1317+ Config : testAccCGCSnippet_storageStaticWebsiteExample (context ),
1318+ },
1319+ {
1320+ ResourceName : "google_storage_bucket.static_website" ,
1321+ ImportState : true ,
1322+ ImportStateVerify : true ,
1323+ },
1324+ },
1325+ })
1326+ }
1327+
1328+ func testAccCGCSnippet_storageStaticWebsiteExample (context map [string ]interface {}) string {
1329+ return Nprintf (`
1330+ # Create new storage bucket in the US multi-region
1331+ # with coldline storage and settings for main_page_suffix and not_found_page
1332+ resource "google_storage_bucket" "static_website" {
1333+ name = "tf-test-static-website-bucket%{random_suffix}"
1334+ location = "US"
1335+ storage_class = "COLDLINE"
1336+ website {
1337+ main_page_suffix = "index.html%{random_suffix}"
1338+ not_found_page = "index.html%{random_suffix}"
1339+ }
1340+ }
1341+
1342+ # Make bucket public by granting allUsers READER access
1343+ resource "google_storage_bucket_access_control" "public_rule" {
1344+ bucket = google_storage_bucket.static_website.id
1345+ role = "READER"
1346+ entity = "allUsers"
1347+ }
1348+
1349+ # Upload a simple index.html page to the bucket
1350+ resource "google_storage_bucket_object" "indexpage" {
1351+ name = "index.html%{random_suffix}"
1352+ content = "<html><body>Hello World!</body></html>"
1353+ content_type = "text/html"
1354+ bucket = google_storage_bucket.static_website.id
1355+ }
1356+
1357+ # Upload a simple 404 / error page to the bucket
1358+ resource "google_storage_bucket_object" "errorpage" {
1359+ name = "404.html%{random_suffix}"
1360+ content = "<html><body>404!</body></html>"
1361+ content_type = "text/html"
1362+ bucket = google_storage_bucket.static_website.id
1363+ }
1364+ ` , context )
1365+ }
0 commit comments