forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Firebase Hosting site Terraform provider (GoogleCloudPlatform#6598)
* Firebase Hosting site Terraform provider * Add sweeper to Firebase Hosting Site * Add a basic hosting site without app * Move app_id to test_vars_overrides to avoid adding random_suffix * Add defaultUrl. Shorten base_url. Add sites/site-id import * Create new web app as part of hosting site test * Fix tab vs spaces * Separate basic and full test for firebasehosting * Add update test for google_firebase_hosting_site * Use immediate delete for test web app * Use deletion_policy = DELETE for handwritten update test * Address feedack on site_id name * Use specific Firebase Hosting docs
- Loading branch information
1 parent
514025e
commit dd89f21
Showing
5 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2018 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Product | ||
name: FirebaseHosting | ||
display_name: Firebase Hosting | ||
versions: | ||
- !ruby/object:Api::Product::Version | ||
name: beta | ||
base_url: https://firebasehosting.googleapis.com/v1beta1/ | ||
scopes: | ||
- https://www.googleapis.com/auth/cloud-platform | ||
objects: | ||
- !ruby/object:Api::Resource | ||
name: 'Site' | ||
min_version: beta | ||
base_url: projects/{{project}}/sites | ||
self_link: projects/{{project}}/sites/{{site_id}} | ||
create_url: projects/{{project}}/sites?siteId={{site_id}} | ||
update_verb: :PATCH | ||
update_mask: true | ||
description: 'A `Site` represents a Firebase Hosting site.' | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Official Documentation': | ||
'https://firebase.google.com/docs/hosting' | ||
api: 'https://firebase.google.com/docs/reference/hosting/rest/v1beta1/projects.sites' | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: 'site_id' | ||
description: | | ||
Required. Immutable. A globally unique identifier for the Hosting site. This identifier is | ||
used to construct the Firebase-provisioned subdomains for the site, so it must also be a valid | ||
domain name label. | ||
input: true | ||
url_param_only: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: name | ||
description: | | ||
Output only. The fully-qualified resource name of the Hosting site, in the | ||
format: projects/PROJECT_IDENTIFIER/sites/SITE_ID PROJECT_IDENTIFIER: the | ||
Firebase project's | ||
[`ProjectNumber`](https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects#FirebaseProject.FIELDS.project_number) ***(recommended)*** or its | ||
[`ProjectId`](https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects#FirebaseProject.FIELDS.project_id). | ||
Learn more about using project identifiers in Google's | ||
[AIP 2510 standard](https://google.aip.dev/cloud/2510). | ||
output: true | ||
- !ruby/object:Api::Type::String | ||
name: appId | ||
description: | | ||
Optional. The [ID of a Web App](https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.webApps#WebApp.FIELDS.app_id) | ||
associated with the Hosting site. | ||
- !ruby/object:Api::Type::String | ||
name: defaultUrl | ||
output: true | ||
description: The default URL for the site in the form of https://{name}.web.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2017 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Provider::Terraform::Config | ||
overrides: !ruby/object:Overrides::ResourceOverrides | ||
Site: !ruby/object:Overrides::Terraform::ResourceOverride | ||
import_format: ['projects/{{project}}/sites/{{site_id}}', 'sites/{{site_id}}', '{{site_id}}'] | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: "firebasehosting_site_basic" | ||
min_version: "beta" | ||
primary_resource_id: "default" | ||
vars: | ||
site_id: site-no-app | ||
test_env_vars: | ||
project_id: :PROJECT_NAME | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: "firebasehosting_site_full" | ||
min_version: "beta" | ||
primary_resource_id: "full" | ||
vars: | ||
site_id: site-with-app | ||
test_env_vars: | ||
project_id: :PROJECT_NAME | ||
# This is for copying files over | ||
files: !ruby/object:Provider::Config::Files | ||
# These files have templating (ERB) code that will be run. | ||
# This is usually to add licensing info, autogeneration notices, etc. | ||
compile: | ||
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> |
5 changes: 5 additions & 0 deletions
5
mmv1/templates/terraform/examples/firebasehosting_site_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "google_firebase_hosting_site" "default" { | ||
provider = google-beta | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
site_id = "<%= ctx[:vars]['site_id'] %>" | ||
} |
13 changes: 13 additions & 0 deletions
13
mmv1/templates/terraform/examples/firebasehosting_site_full.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "google_firebase_web_app" "default" { | ||
provider = google-beta | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
display_name = "Test web app for Firebase Hosting" | ||
deletion_policy = "DELETE" | ||
} | ||
|
||
resource "google_firebase_hosting_site" "full" { | ||
provider = google-beta | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
site_id = "<%= ctx[:vars]['site_id'] %>" | ||
app_id = google_firebase_web_app.default.app_id | ||
} |
83 changes: 83 additions & 0 deletions
83
mmv1/third_party/terraform/tests/resource_firebase_hosting_site_test.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<% autogen_exception -%> | ||
package google | ||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccFirebaseHostingSite_firebasehostingSiteUpdate(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"project_id": getTestProjectFromEnv(), | ||
"random_suffix": randString(t, 10), | ||
"site_id": "tf-test-site-update-app", | ||
} | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProvidersOiCS, | ||
CheckDestroy: testAccCheckFirebaseHostingSiteDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFirebaseHostingSite_firebasehostingSiteBeforeUpdate(context), | ||
}, | ||
{ | ||
ResourceName: "google_firebase_hosting_site.update", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"site_id"}, | ||
}, | ||
{ | ||
Config: testAccFirebaseHostingSite_firebasehostingSiteAfterUpdate(context), | ||
}, | ||
{ | ||
ResourceName: "google_firebase_hosting_site.update", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"site_id"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccFirebaseHostingSite_firebasehostingSiteBeforeUpdate(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_firebase_web_app" "before" { | ||
provider = google-beta | ||
project = "%{project_id}" | ||
display_name = "Test web app before for Firebase Hosting" | ||
deletion_policy = "DELETE" | ||
} | ||
|
||
resource "google_firebase_hosting_site" "update" { | ||
provider = google-beta | ||
project = "%{project_id}" | ||
site_id = "%{site_id}%{random_suffix}" | ||
app_id = google_firebase_web_app.before.app_id | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccFirebaseHostingSite_firebasehostingSiteAfterUpdate(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_firebase_web_app" "after" { | ||
provider = google-beta | ||
project = "%{project_id}" | ||
display_name = "Test web app after for Firebase Hosting" | ||
deletion_policy = "DELETE" | ||
} | ||
|
||
resource "google_firebase_hosting_site" "update" { | ||
provider = google-beta | ||
project = "%{project_id}" | ||
site_id = "%{site_id}%{random_suffix}" | ||
app_id = google_firebase_web_app.after.app_id | ||
} | ||
`, context) | ||
} | ||
|
||
<% end -%> |