Skip to content

Commit

Permalink
deletion_policy breaking changes for Firebase apps
Browse files Browse the repository at this point in the history
  • Loading branch information
rainshen49 committed Jul 27, 2023
1 parent 0040570 commit d68c689
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 76 deletions.
9 changes: 5 additions & 4 deletions mmv1/products/firebase/AndroidApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ examples:
vars:
display_name: 'Display Name Basic'
test_env_vars:
org_id: :ORG_ID
project_id: :PROJECT_NAME
test_vars_overrides:
package_name: '"android.package.app" + acctest.RandString(t, 4)'
Expand All @@ -73,14 +72,16 @@ examples:
- project
- deletion_policy
virtual_fields:
# TODO: make this an enum in a future major version. If using this field as a reference, look at PerInstanceConfig's minimal_action field for enum configuration.
- !ruby/object:Api::Type::String
- !ruby/object:Api::Type::Enum
name: 'deletion_policy'
description: |
(Optional) Set to `ABANDON` to allow the AndroidApp to be untracked from terraform state
rather than deleted upon `terraform destroy`. This is useful because the AndroidApp may be
serving traffic. Set to `DELETE` to delete the AndroidApp. Defaults to `DELETE`.
default_value: DELETE
default_value: :DELETE
values:
- :DELETE
- :ABANDON
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_delete: templates/terraform/custom_delete/firebase_app_deletion_policy.erb
properties:
Expand Down
10 changes: 5 additions & 5 deletions mmv1/products/firebase/AppleApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ examples:
display_name: 'Display Name Basic'
bundle_id: 'apple.app.12345'
test_env_vars:
org_id: :ORG_ID
project_id: :PROJECT_NAME
test_vars_overrides:
display_name: '"tf-test Display Name Basic"'
Expand All @@ -79,7 +78,6 @@ examples:
app_store_id: '12345'
team_id: '9987654321' # Has to be a 10-digit number.
test_env_vars:
org_id: :ORG_ID
project_id: :PROJECT_NAME
test_vars_overrides:
app_store_id: '12345'
Expand All @@ -89,14 +87,16 @@ examples:
- project
- deletion_policy
virtual_fields:
# TODO: make this an enum in a future major version. If using this field as a reference, look at PerInstanceConfig's minimal_action field for enum configuration.
- !ruby/object:Api::Type::String
- !ruby/object:Api::Type::Enum
name: 'deletion_policy'
description: |
(Optional) Set to `ABANDON` to allow the Apple to be untracked from terraform state
rather than deleted upon `terraform destroy`. This is useful because the Apple may be
serving traffic. Set to `DELETE` to delete the Apple. Defaults to `DELETE`.
default_value: DELETE
default_value: :DELETE
values:
- :DELETE
- :ABANDON
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_delete: templates/terraform/custom_delete/firebase_app_deletion_policy.erb
properties:
Expand Down
13 changes: 7 additions & 6 deletions mmv1/products/firebase/WebApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,24 @@ examples:
vars:
display_name: 'Display Name Basic'
bucket_name: 'fb-webapp-'
project_name: "my-project"
test_env_vars:
org_id: :ORG_ID
project_id: :PROJECT_NAME
test_vars_overrides:
display_name: '"tf-test Display Name Basic"'
ignore_read_extra:
- project
- deletion_policy
virtual_fields:
# TODO: make this an enum in a future major version. If using this field as a reference, look at PerInstanceConfig's minimal_action field for enum configuration.
- !ruby/object:Api::Type::String
- !ruby/object:Api::Type::Enum
name: 'deletion_policy'
description: |
Set to `ABANDON` to allow the WebApp to be untracked from terraform state
rather than deleted upon `terraform destroy`. This is useful becaue the WebApp may be
serving traffic. Set to `DELETE` to delete the WebApp. Default to `ABANDON`
default_value: ABANDON
serving traffic. Set to `DELETE` to delete the WebApp. Default to `DELETE`
default_value: :DELETE
values:
- :DELETE
- :ABANDON
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_delete: templates/terraform/custom_delete/firebase_app_deletion_policy.erb
properties:
Expand Down
22 changes: 1 addition & 21 deletions mmv1/templates/terraform/examples/firebase_web_app_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
resource "google_project" "default" {
provider = google-beta

project_id = "<%= ctx[:vars]['project_name'] %>"
name = "<%= ctx[:vars]['project_name'] %>"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"

labels = {
"firebase" = "enabled"
}
}

resource "google_firebase_project" "default" {
provider = google-beta
project = google_project.default.project_id
}

resource "google_firebase_web_app" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
project = google_project.default.project_id
project = "<%= ctx[:test_env_vars]['project_id'] %>"
display_name = "<%= ctx[:vars]['display_name'] %>"
deletion_policy = "DELETE"

depends_on = [google_firebase_project.default]
}

data "google_firebase_web_app_config" "basic" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ resource "google_firebase_web_app" "default" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project_id'] %>"
display_name = "<%= ctx[:vars]['display_name'] %>"
deletion_policy = "DELETE"
}

resource "google_firebase_hosting_site" "full" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func testAccDataSourceGoogleFirebaseWebApp(context map[string]interface{}) strin
resource "google_firebase_web_app" "my_app" {
project = "%{project_id}"
display_name = "%{display_name}"
deletion_policy = "DELETE"
}

data "google_firebase_web_app" "my_app" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ resource "google_firebase_web_app" "before" {
provider = google-beta
project = "%{project_id}"
display_name = "tf-test Test web app before for Firebase Hosting"
deletion_policy = "DELETE"
}

resource "google_firebase_hosting_site" "update" {
Expand All @@ -70,7 +69,6 @@ resource "google_firebase_web_app" "after" {
provider = google-beta
project = "%{project_id}"
display_name = "tf-test Test web app after for Firebase Hosting"
deletion_policy = "DELETE"
}

resource "google_firebase_hosting_site" "update" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,19 @@ func TestAccFirebaseWebApp_firebaseWebAppFull(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
"project_id": envvar.GetTestProjectFromEnv(),
"random_suffix": acctest.RandString(t, 10),
"display_name": "tf-test Display Name N",
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"google": {
VersionConstraint: "4.58.0",
Source: "hashicorp/google<%= "-" + version unless version == 'ga' -%>",
},
},
Config: testAccFirebaseWebApp_firebaseWebAppFull(context, ""),
},
{
ExternalProviders: map[string]resource.ExternalProvider{
"google": {
VersionConstraint: "4.58.0",
Source: "hashicorp/google<%= "-" + version unless version == 'ga' -%>",
},
},
Config: testAccFirebaseWebApp_firebaseWebAppFull(context, "2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.google_firebase_web_app_config.default", "api_key"),
Expand All @@ -54,11 +43,9 @@ func TestAccFirebaseWebApp_firebaseWebAppFull(t *testing.T) {
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Config: testAccFirebaseWebApp_firebaseWebAppFull(context, ""),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Config: testAccFirebaseWebApp_firebaseWebAppFull(context, "2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.google_firebase_web_app_config.default", "api_key"),
Expand All @@ -73,28 +60,11 @@ func TestAccFirebaseWebApp_firebaseWebAppFull(t *testing.T) {
func testAccFirebaseWebApp_firebaseWebAppFull(context map[string]interface{}, update string) string {
context["display_name"] = context["display_name"].(string) + update
return acctest.Nprintf(`
resource "google_project" "default" {
provider = google-beta

project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
labels = {
"firebase" = "enabled"
}
}

resource "google_firebase_project" "default" {
provider = google-beta
project = google_project.default.project_id
}

resource "google_firebase_web_app" "default" {
provider = google-beta
project = google_project.default.project_id
project = "%{project_id}"
display_name = "%{display_name} %{random_suffix}"

depends_on = [google_firebase_project.default]
deletion_policy = "DELETE"
}

data "google_firebase_web_app_config" "default" {
Expand All @@ -108,7 +78,7 @@ func TestAccFirebaseWebApp_firebaseWebAppSkipDelete(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project_id": envvar.GetTestProjectFromEnv(),
"org_id": envvar.GetTestOrgFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
"display_name": "tf-test Display Name N",
}
Expand All @@ -132,11 +102,29 @@ func TestAccFirebaseWebApp_firebaseWebAppSkipDelete(t *testing.T) {
}

func testAccFirebaseWebApp_firebaseWebAppSkipDelete(context map[string]interface{}, update string) string {
// Create a new project so we can clean up the project entirely
return acctest.Nprintf(`
resource "google_project" "default" {
provider = google-beta

project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
labels = {
"firebase" = "enabled"
}
}

resource "google_firebase_project" "default" {
provider = google-beta
project = google_project.default.project_id
}

resource "google_firebase_web_app" "skip_delete" {
provider = google-beta
project = "%{project_id}"
project = google_firebase_project.default.project
display_name = "%{display_name} %{random_suffix}"
deletion_policy = "ABANDON"
}
`, context)
}
Expand Down

0 comments on commit d68c689

Please sign in to comment.