11package google
22
33import (
4- "fmt"
54 "github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
65 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
76 "testing"
@@ -10,46 +9,70 @@ import (
109func TestAccAppEngineFlexibleAppVersion_update (t * testing.T ) {
1110 t .Parallel ()
1211
13- resourceName := fmt .Sprintf ("tf-test-ae-service-%s" , acctest .RandString (10 ))
12+ context := map [string ]interface {}{
13+ "org_id" : getTestOrgFromEnv (t ),
14+ "billing_account" : getTestBillingAccountFromEnv (t ),
15+ "random_suffix" : acctest .RandString (10 ),
16+ }
1417
1518 resource .Test (t , resource.TestCase {
1619 PreCheck : func () { testAccPreCheck (t ) },
1720 Providers : testAccProviders ,
1821 CheckDestroy : testAccCheckAppEngineFlexibleAppVersionDestroy ,
1922 Steps : []resource.TestStep {
2023 {
21- Config : testAccAppEngineFlexibleAppVersion_python (resourceName ),
24+ Config : testAccAppEngineFlexibleAppVersion_python (context ),
2225 },
2326 {
2427 ResourceName : "google_app_engine_flexible_app_version.foo" ,
2528 ImportState : true ,
2629 ImportStateVerify : true ,
27- ImportStateVerifyIgnore : []string {"env_variables" , "deployment" , "entrypoint" , "service" , "delete_service_on_destroy " },
30+ ImportStateVerifyIgnore : []string {"env_variables" , "deployment" , "entrypoint" , "service" , "noop_on_destroy " },
2831 },
2932 {
30- Config : testAccAppEngineFlexibleAppVersion_pythonUpdate (resourceName ),
33+ Config : testAccAppEngineFlexibleAppVersion_pythonUpdate (context ),
3134 },
3235 {
3336 ResourceName : "google_app_engine_flexible_app_version.foo" ,
3437 ImportState : true ,
3538 ImportStateVerify : true ,
36- ImportStateVerifyIgnore : []string {"env_variables" , "deployment" , "entrypoint" , "service" , "delete_service_on_destroy " },
39+ ImportStateVerifyIgnore : []string {"env_variables" , "deployment" , "entrypoint" , "service" , "noop_on_destroy " },
3740 },
3841 },
3942 })
4043}
4144
42- func testAccAppEngineFlexibleAppVersion_python (resourceName string ) string {
43- return fmt .Sprintf (`
45+ func testAccAppEngineFlexibleAppVersion_python (context map [string ]interface {}) string {
46+ return Nprintf (`
47+ resource "google_project" "my_project" {
48+ name = "tf-test-appeng-flex%{random_suffix}"
49+ project_id = "tf-test-appeng-flex%{random_suffix}"
50+ org_id = "%{org_id}"
51+ billing_account = "%{billing_account}"
52+ }
53+
54+ resource "google_app_engine_application" "app" {
55+ project = google_project.my_project.project_id
56+ location_id = "us-central"
57+ }
58+
4459resource "google_project_service" "project" {
60+ project = google_project.my_project.project_id
4561 service = "appengineflex.googleapis.com"
4662
4763 disable_dependent_services = false
4864}
4965
66+ resource "google_project_iam_member" "gae_api" {
67+ project = google_project_service.project.project
68+ role = "roles/compute.networkUser"
69+ member = "serviceAccount:service-${google_project.my_project.number}@gae-api-prod.google.com.iam.gserviceaccount.com"
70+ }
71+
5072resource "google_app_engine_flexible_app_version" "foo" {
73+ project = google_project_iam_member.gae_api.project
5174 version_id = "v1"
52- service = "%s "
75+ service = "default "
5376 runtime = "python"
5477
5578 runtime_api_version = "1"
@@ -104,11 +127,12 @@ resource "google_app_engine_flexible_app_version" "foo" {
104127 instances = 1
105128 }
106129
107- delete_service_on_destroy = true
130+ noop_on_destroy = true
108131}
109132
110133resource "google_storage_bucket" "bucket" {
111- name = "%s-bucket"
134+ project = google_project.my_project.project_id
135+ name = "tf-test-%{random_suffix}-flex-ae-bucket"
112136}
113137
114138resource "google_storage_bucket_object" "yaml" {
@@ -127,20 +151,40 @@ resource "google_storage_bucket_object" "main" {
127151 name = "main.py"
128152 bucket = google_storage_bucket.bucket.name
129153 source = "./test-fixtures/appengine/hello-world-flask/main.py"
130- }` , resourceName , resourceName )
154+ }` , context )
155+ }
156+
157+ func testAccAppEngineFlexibleAppVersion_pythonUpdate (context map [string ]interface {}) string {
158+ return Nprintf (`
159+ resource "google_project" "my_project" {
160+ name = "tf-test-appeng-flex%{random_suffix}"
161+ project_id = "tf-test-appeng-flex%{random_suffix}"
162+ org_id = "%{org_id}"
163+ billing_account = "%{billing_account}"
164+ }
165+
166+ resource "google_app_engine_application" "app" {
167+ project = google_project.my_project.project_id
168+ location_id = "us-central"
131169}
132170
133- func testAccAppEngineFlexibleAppVersion_pythonUpdate (resourceName string ) string {
134- return fmt .Sprintf (`
135171resource "google_project_service" "project" {
172+ project = google_project.my_project.project_id
136173 service = "appengineflex.googleapis.com"
137174
138175 disable_dependent_services = false
139176}
140177
178+ resource "google_project_iam_member" "gae_api" {
179+ project = google_project_service.project.project
180+ role = "roles/compute.networkUser"
181+ member = "serviceAccount:service-${google_project.my_project.number}@gae-api-prod.google.com.iam.gserviceaccount.com"
182+ }
183+
141184resource "google_app_engine_flexible_app_version" "foo" {
185+ project = google_project_iam_member.gae_api.project
142186 version_id = "v1"
143- service = "%s "
187+ service = "default "
144188 runtime = "python"
145189
146190 runtime_api_version = "1"
@@ -195,11 +239,12 @@ resource "google_app_engine_flexible_app_version" "foo" {
195239 instances = 2
196240 }
197241
198- delete_service_on_destroy = true
242+ noop_on_destroy = true
199243}
200244
201245resource "google_storage_bucket" "bucket" {
202- name = "%s-bucket"
246+ project = google_project.my_project.project_id
247+ name = "tf-test-%{random_suffix}-flex-ae-bucket"
203248}
204249
205250resource "google_storage_bucket_object" "yaml" {
@@ -218,5 +263,5 @@ resource "google_storage_bucket_object" "main" {
218263 name = "main.py"
219264 bucket = google_storage_bucket.bucket.name
220265 source = "./test-fixtures/appengine/hello-world-flask/main.py"
221- }` , resourceName , resourceName )
266+ }` , context )
222267}
0 commit comments