Skip to content

Commit

Permalink
Firebase hosting channel (GoogleCloudPlatform#6791)
Browse files Browse the repository at this point in the history
* Firebase Hosting Channels

* Use references site_id

* Add handwritten update test

* Use billing_project instead of project

* Remove dependence on a project
  • Loading branch information
rainshen49 authored and googlerjk committed Nov 21, 2022
1 parent 70264b3 commit 3b9f1d3
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 1 deletion.
67 changes: 66 additions & 1 deletion mmv1/products/firebasehosting/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,69 @@ objects:
- !ruby/object:Api::Type::String
name: defaultUrl
output: true
description: The default URL for the site in the form of https://{name}.web.app
description: The default URL for the site in the form of https://{name}.web.app
- !ruby/object:Api::Resource
name: 'Channel'
min_version: beta
base_url: sites/{{site_id}}/channels
self_link: sites/{{site_id}}/channels/{{channel_id}}
create_url: sites/{{site_id}}/channels?channelId={{channel_id}}
update_verb: :PATCH
update_mask: true
description: |
A `Channel` represents a stream of releases for a site. All sites have a default
`live` channel that serves content to the Firebase-provided subdomains and any
connected custom domains.
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/sites.channels'
parameters:
- !ruby/object:Api::Type::String
name: site_id
description: |
Required. The ID of the site in which to create this channel.
input: true
required: true
url_param_only: true
- !ruby/object:Api::Type::String
name: channel_id
description: |
Required. Immutable. A unique ID within the site that identifies the channel.
input: true
required: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: name
pattern: sites/{{site_id}}/channels/{{channel_id}}
description: |
The fully-qualified resource name for the channel, in the format:
sites/SITE_ID/channels/CHANNEL_ID
output: true
- !ruby/object:Api::Type::Integer
name: retainedReleaseCount
description: |
The number of previous releases to retain on the channel for rollback or other
purposes. Must be a number between 1-100. Defaults to 10 for new channels.
- !ruby/object:Api::Type::KeyValuePairs
name: labels
description: Text labels used for extra metadata and/or filtering
- !ruby/object:Api::Type::Time
name: expireTime
conflicts:
- ttl
description: |
The time at which the channel will be automatically deleted. If null, the channel
will not be automatically deleted. This field is present in the output whether it's
set directly or via the `ttl` field.
- !ruby/object:Api::Type::String
name: ttl
conflicts:
- expireTime
input: true
description: |
Input only. A time-to-live for this channel. Sets `expire_time` to the provided
duration past the time of the request. A duration in seconds with up to nine fractional
digits, terminated by 's'. Example: "86400s" (one day).
28 changes: 28 additions & 0 deletions mmv1/products/firebasehosting/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ overrides: !ruby/object:Overrides::ResourceOverrides
site_id: site-with-app
test_env_vars:
project_id: :PROJECT_NAME
Channel: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ['sites/{{site_id}}/channels/{{channel_id}}']
properties:
expireTime: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true # API computes value from ttl if not set directly
retainedReleaseCount: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true # unlimited for "live" channel created with the site, and 10 for subsequent channels
ttl: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true # API doesn't return this value
examples:
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_channel_basic"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-with-channel
channel_id: channel-basic
test_env_vars:
project_id: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_channel_full"
min_version: "beta"
primary_resource_id: "full"
vars:
site_id: site-with-channel
channel_id: channel-full
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project_id'] %>"
site_id = "<%= ctx[:vars]['site_id'] %>"
}

resource "google_firebase_hosting_channel" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "<%= ctx[:vars]['channel_id'] %>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project_id'] %>"
site_id = "<%= ctx[:vars]['site_id'] %>"
}

resource "google_firebase_hosting_channel" "full" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "<%= ctx[:vars]['channel_id'] %>"
ttl = "86400s"
retained_release_count = 20
labels = {
"some-key": "some-value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccFirebaseHostingChannel_firebasehostingChannelUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project_id": getTestProjectFromEnv(),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckFirebaseHostingChannelDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelBasic(context),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelTtl(context, "8600s"),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelTtl(context, "86400s"),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelRetainedReleaseCount(context, 30),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelRetainedReleaseCount(context, 20),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelLabels(context),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelMultipleFields(context),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
{
Config: testAccFirebaseHostingChannel_firebasehostingChannelBasic(context),
},
{
ResourceName: "google_firebase_hosting_channel.update",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl", "site_id", "channel_id"},
},
},
})
}

func testAccFirebaseHostingChannel_firebasehostingChannelBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "%{project_id}"
site_id = "tf-test-site-with-channel%{random_suffix}"
}

resource "google_firebase_hosting_channel" "update" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "tf-test-channel-update%{random_suffix}"
}
`, context)
}

func testAccFirebaseHostingChannel_firebasehostingChannelTtl(context map[string]interface{}, ttl string) string {
context["ttl"] = ttl
return Nprintf(`
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "%{project_id}"
site_id = "tf-test-site-with-channel%{random_suffix}"
}

resource "google_firebase_hosting_channel" "update" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "tf-test-channel-update%{random_suffix}"
ttl = "%{ttl}"
}
`, context)
}

func testAccFirebaseHostingChannel_firebasehostingChannelRetainedReleaseCount(context map[string]interface{}, retainedReleaseCount int) string {
context["retained_release_count"] = retainedReleaseCount
return Nprintf(`
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "%{project_id}"
site_id = "tf-test-site-with-channel%{random_suffix}"
}

resource "google_firebase_hosting_channel" "update" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "tf-test-channel-update%{random_suffix}"
ttl = "86400s"
retained_release_count = %{retained_release_count}
}
`, context)
}

func testAccFirebaseHostingChannel_firebasehostingChannelLabels(context map[string]interface{}) string {
return Nprintf(`
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "%{project_id}"
site_id = "tf-test-site-with-channel%{random_suffix}"
}

resource "google_firebase_hosting_channel" "update" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "tf-test-channel-update%{random_suffix}"
ttl = "86400s"
retained_release_count = 10
labels = {
"some-key": "some-value"
}
}
`, context)
}

func testAccFirebaseHostingChannel_firebasehostingChannelMultipleFields(context map[string]interface{}) string {
return Nprintf(`
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "%{project_id}"
site_id = "tf-test-site-with-channel%{random_suffix}"
}

resource "google_firebase_hosting_channel" "update" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "tf-test-channel-update%{random_suffix}"
ttl = "86400s"
retained_release_count = 40
labels = {
"some-key-2": "some-value-2"
}
}
`, context)
}

<% end -%>

0 comments on commit 3b9f1d3

Please sign in to comment.