Skip to content

Commit

Permalink
Add disable_on_destroy flag to project_services (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo authored Apr 4, 2018
1 parent 0cac59d commit 1bf076f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
12 changes: 12 additions & 0 deletions google/resource_google_project_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions google/resource_google_project_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
}
Expand Down

0 comments on commit 1bf076f

Please sign in to comment.