mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
9ceb644460
Deprecate the app_engine sub-block of google_project, and create a google_app_engine_application resource instead. Also, add some tests for its behaviour, as well as some documentation for it. Note that this is largely an implementation of the ideas discussed in #2118, except we're not using CustomizeDiff to reject deletions without our special flag set, because CustomizeDiff apparently doesn't run on Delete. Who knew? This leaves us rejecting the deletion at apply time, which is less than ideal, but the only other option I see is to silently not delete the resource, and that's... not ideal, either. This also stops the app_engine sub-block on google_project from forcing new when it's removed, and sets it to computed, so users can safely move from using the sub-block to using the resource without state surgery or deleting their entire project. This does mean it's impossible to delete an App Engine application from a sub-block now, but seeing as that was the same situation before, and we just papered over it by making the project recreate itself in that situation, and people Were Not Fans of that, I'm considering that an acceptable casualty.
124 lines
3.5 KiB
Go
124 lines
3.5 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccAppEngineApplication_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
org := getTestOrgFromEnv(t)
|
|
pid := acctest.RandomWithPrefix("tf-test")
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccAppEngineApplication_basic(pid, org),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttrSet("google_app_engine_application.acceptance", "url_dispatch_rule.#"),
|
|
resource.TestCheckResourceAttrSet("google_app_engine_application.acceptance", "name"),
|
|
resource.TestCheckResourceAttrSet("google_app_engine_application.acceptance", "code_bucket"),
|
|
resource.TestCheckResourceAttrSet("google_app_engine_application.acceptance", "default_hostname"),
|
|
resource.TestCheckResourceAttrSet("google_app_engine_application.acceptance", "default_bucket"),
|
|
),
|
|
},
|
|
{
|
|
ResourceName: "google_app_engine_application.acceptance",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
ImportStateVerifyIgnore: []string{"ack_delete_noop"},
|
|
},
|
|
{
|
|
Config: testAccAppEngineApplication_update(pid, org),
|
|
},
|
|
{
|
|
ResourceName: "google_app_engine_application.acceptance",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
ImportStateVerifyIgnore: []string{"ack_delete_noop"},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAppEngineApplication_delete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
org := getTestOrgFromEnv(t)
|
|
pid := acctest.RandomWithPrefix("tf-test")
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccAppEngineApplication_noDelete(pid, org),
|
|
},
|
|
{
|
|
Config: testAccAppEngineApplication_noDelete(pid, org),
|
|
Destroy: true,
|
|
ExpectError: regexp.MustCompile("set the `ack_delete_noop` field to true"),
|
|
},
|
|
{
|
|
// revert back to the same config, but with delete set, so the project can get deleted
|
|
Config: testAccAppEngineApplication_basic(pid, org),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccAppEngineApplication_basic(pid, org string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_project" "acceptance" {
|
|
project_id = "%s"
|
|
name = "%s"
|
|
org_id = "%s"
|
|
}
|
|
|
|
resource "google_app_engine_application" "acceptance" {
|
|
project = "${google_project.acceptance.project_id}"
|
|
auth_domain = "hashicorptest.com"
|
|
location_id = "us-central"
|
|
serving_status = "SERVING"
|
|
ack_delete_noop = true
|
|
}`, pid, pid, org)
|
|
}
|
|
|
|
func testAccAppEngineApplication_update(pid, org string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_project" "acceptance" {
|
|
project_id = "%s"
|
|
name = "%s"
|
|
org_id = "%s"
|
|
}
|
|
|
|
resource "google_app_engine_application" "acceptance" {
|
|
project = "${google_project.acceptance.project_id}"
|
|
auth_domain = "tf-test.club"
|
|
location_id = "us-central"
|
|
serving_status = "USER_DISABLED"
|
|
ack_delete_noop = true
|
|
}`, pid, pid, org)
|
|
}
|
|
|
|
func testAccAppEngineApplication_noDelete(pid, org string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_project" "acceptance" {
|
|
project_id = "%s"
|
|
name = "%s"
|
|
org_id = "%s"
|
|
}
|
|
|
|
resource "google_app_engine_application" "acceptance" {
|
|
project = "${google_project.acceptance.project_id}"
|
|
auth_domain = "hashicorptest.com"
|
|
location_id = "us-central"
|
|
serving_status = "SERVING"
|
|
}`, pid, pid, org)
|
|
}
|