From 1bf076f6a975f019fcac6218fcd32423992bc480 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Wed, 4 Apr 2018 16:20:13 -0700 Subject: [PATCH] Add disable_on_destroy flag to project_services (#1293) --- google/resource_google_project_services.go | 12 ++++++++++++ google/resource_google_project_services_test.go | 17 +++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/google/resource_google_project_services.go b/google/resource_google_project_services.go index c6c9068ef00..b28336b2e7a 100644 --- a/google/resource_google_project_services.go +++ b/google/resource_google_project_services.go @@ -30,6 +30,11 @@ func resourceGoogleProjectServices() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, + "disable_on_destroy": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, }, } } @@ -105,6 +110,13 @@ func resourceGoogleProjectServicesUpdate(d *schema.ResourceData, meta interface{ func resourceGoogleProjectServicesDelete(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG]: Deleting google_project_services") + + if disable := d.Get("disable_on_destroy"); !(disable.(bool)) { + log.Printf("Not disabling service '%s', because disable_on_destroy is false.", d.Id()) + d.SetId("") + return nil + } + config := meta.(*Config) services := resourceServices(d) for _, s := range services { diff --git a/google/resource_google_project_services_test.go b/google/resource_google_project_services_test.go index 2196aa2415a..a591357e5e8 100644 --- a/google/resource_google_project_services_test.go +++ b/google/resource_google_project_services_test.go @@ -224,11 +224,11 @@ func testAccProjectAssociateServicesBasic(services []string, pid, name, org stri return fmt.Sprintf(` resource "google_project" "acceptance" { project_id = "%s" - name = "%s" - org_id = "%s" + name = "%s" + org_id = "%s" } resource "google_project_services" "acceptance" { - project = "${google_project.acceptance.project_id}" + project = "${google_project.acceptance.project_id}" services = [%s] } `, pid, name, org, testStringsToString(services)) @@ -237,14 +237,15 @@ resource "google_project_services" "acceptance" { func testAccProjectAssociateServicesBasic_withBilling(services []string, pid, name, org, billing string) string { return fmt.Sprintf(` resource "google_project" "acceptance" { - project_id = "%s" - name = "%s" - org_id = "%s" + project_id = "%s" + name = "%s" + org_id = "%s" billing_account = "%s" } resource "google_project_services" "acceptance" { - project = "${google_project.acceptance.project_id}" - services = [%s] + project = "${google_project.acceptance.project_id}" + services = [%s] + disable_on_destroy = false } `, pid, name, org, billing, testStringsToString(services)) }