@@ -23,171 +23,6 @@ import (
2323 "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
2424)
2525
26- func TestAccComputeGlobalForwardingRule_externalCdnLbWithBackendBucketExample (t * testing.T ) {
27- t .Parallel ()
28-
29- context := map [string ]interface {}{
30- "random_suffix" : randString (t , 10 ),
31- }
32-
33- vcrTest (t , resource.TestCase {
34- PreCheck : func () { testAccPreCheck (t ) },
35- Providers : testAccProvidersOiCS ,
36- CheckDestroy : testAccCheckComputeGlobalForwardingRuleDestroyProducer (t ),
37- Steps : []resource.TestStep {
38- {
39- Config : testAccComputeGlobalForwardingRule_externalCdnLbWithBackendBucketExample (context ),
40- },
41- {
42- ResourceName : "google_compute_global_forwarding_rule.default" ,
43- ImportState : true ,
44- ImportStateVerify : true ,
45- ImportStateVerifyIgnore : []string {"network" , "port_range" , "target" , "ip_address" },
46- },
47- },
48- })
49- }
50-
51- func testAccComputeGlobalForwardingRule_externalCdnLbWithBackendBucketExample (context map [string ]interface {}) string {
52- return Nprintf (`
53- # CDN load balancer with Cloud bucket as backend
54-
55- # VPC
56- resource "google_compute_network" "default" {
57- name = "tf-test-cdn-network%{random_suffix}"
58- provider = google-beta
59- auto_create_subnetworks = false
60- }
61-
62- # backend subnet
63- resource "google_compute_subnetwork" "default" {
64- name = "tf-test-cdn-subnet%{random_suffix}"
65- provider = google-beta
66- ip_cidr_range = "10.0.1.0/24"
67- region = "us-central1"
68- network = google_compute_network.default.id
69- }
70-
71- # reserve IP address
72- resource "google_compute_global_address" "default" {
73- provider = google-beta
74- name = "tf-test-cdn-static-ip%{random_suffix}"
75- }
76-
77- # forwarding rule
78- resource "google_compute_global_forwarding_rule" "default" {
79- name = "tf-test-cdn-forwarding-rule%{random_suffix}"
80- provider = google-beta
81- ip_protocol = "TCP"
82- load_balancing_scheme = "EXTERNAL"
83- port_range = "80"
84- target = google_compute_target_http_proxy.default.id
85- ip_address = google_compute_global_address.default.id
86- }
87-
88- # http proxy
89- resource "google_compute_target_http_proxy" "default" {
90- name = "tf-test-cdn-target-http-proxy%{random_suffix}"
91- provider = google-beta
92- url_map = google_compute_url_map.default.id
93- }
94-
95- # url map
96- resource "google_compute_url_map" "default" {
97- name = "tf-test-cdn-url-map%{random_suffix}"
98- provider = google-beta
99- default_service = google_compute_backend_bucket.default.id
100- }
101-
102- # backend bucket with CDN policy with default ttl settings
103- resource "google_compute_backend_bucket" "default" {
104- name = "tf-test-image-backend-bucket%{random_suffix}"
105- description = "Contains beautiful images"
106- bucket_name = google_storage_bucket.default.name
107- enable_cdn = true
108- cdn_policy {
109- cache_mode = "CACHE_ALL_STATIC"
110- client_ttl = 3600
111- default_ttl = 3600
112- max_ttl = 86400
113- negative_caching = true
114- serve_while_stale = 86400
115- }
116- }
117-
118- # cdn backend bucket
119- resource "google_storage_bucket" "default" {
120- name = "tf-test-cdn-backend-storage-bucket%{random_suffix}"
121- location = "US"
122- uniform_bucket_level_access = true
123- // delete bucket and contents on destroy.
124- force_destroy = true
125- // Assign specialty files
126- website {
127- main_page_suffix = "index.html"
128- not_found_page = "404.html"
129- }
130- }
131-
132- # make bucket public
133- resource "google_storage_bucket_iam_member" "default" {
134- bucket = google_storage_bucket.default.name
135- role = "roles/storage.objectViewer"
136- member = "allUsers"
137- }
138-
139- resource "google_storage_bucket_object" "index_page" {
140- name = "index.html"
141- source = "index.html"
142- bucket = google_storage_bucket.default.name
143- depends_on = [local_file.index_page]
144- }
145-
146- resource "google_storage_bucket_object" "error_page" {
147- name = "404.html"
148- source = "404.html"
149- bucket = google_storage_bucket.default.name
150- depends_on = [local_file.error_page]
151- }
152-
153- # image object for testing, try to access http://<your_lb_ip_address>/test.jpg
154- resource "google_storage_bucket_object" "test_image" {
155- name = "test.jpg"
156- source = "test.jpg"
157- content_type = "image/jpeg"
158- bucket = google_storage_bucket.default.name
159- depends_on = [null_resource.test_image]
160- }
161-
162- # cdn sample index page
163- resource "local_file" "index_page" {
164- filename = "index.html"
165- content = <<-EOT
166- <html><body>
167- <h1>Congratulations on setting up Google Cloud CDN with Storage backend!</h1>
168- </body></html>
169- EOT
170- }
171-
172- # cdn default error page
173- resource "local_file" "error_page" {
174- filename = "404.html"
175- content = <<-EOT
176- <html><body>
177- <h1>404 Error: Object you are looking for is no longer available!</h1>
178- </body></html>
179- EOT
180- }
181-
182- # cdn sample image
183- resource "null_resource" "test_image" {
184- provisioner "local-exec" {
185- command = "wget -O test.jpg https://upload.wikimedia.org/wikipedia/commons/c/c8/Thank_you_001.jpg"
186- }
187- }
188- ` , context )
189- }
190-
19126func TestAccComputeGlobalForwardingRule_externalTcpProxyLbMigBackendExample (t * testing.T ) {
19227 t .Parallel ()
19328
0 commit comments