Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable_on_destroy flag to project_services #1293

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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