Skip to content

Commit

Permalink
Cloud Run and Cloud Functions integration with Firebase Hosting hashi…
Browse files Browse the repository at this point in the history
  • Loading branch information
rainshen49 authored Feb 21, 2023
1 parent 5cb1565 commit 63a2809
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 0 deletions.
187 changes: 187 additions & 0 deletions mmv1/products/firebasehosting/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,190 @@ objects:
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).
- !ruby/object:Api::Resource
name: "Release"
min_version: beta
base_url: "sites/{{site_id}}/channels/{{channel_id}}/releases"
self_link: "sites/{{site_id}}/channels/{{channel_id}}/releases/{{release_id}}"
create_url: "sites/{{site_id}}/channels/{{channel_id}}/releases?versionName={{version_name}}"
input: true # not updatable
description: |
A Release is a particular collection of configurations that is set to be public at a particular time.
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.releases"
parameters:
- !ruby/object:Api::Type::String
name: site_id
description: |
Required. The ID of the site to which the release belongs.
input: true
required: true
url_param_only: true
- !ruby/object:Api::Type::String
name: channel_id
description: |
The ID of the channel to which the release belongs. If not provided, the release will
belong to the default "live" channel
input: true
url_param_only: true
default_value: 'live'
- !ruby/object:Api::Type::ResourceRef
name: version_name
resource: 'Version'
imports: 'name'
description: |
The unique identifier for a version, in the format: sites/SITE_ID/versions/VERSION_ID.
The content of the version specified will be actively displayed on the appropriate URL.
The Version must belong to the same site as in the `site_id`.
This parameter must be empty if the `type` of the release is `SITE_DISABLE`.
input: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The unique identifier for the release, in either of the following formats:
sites/SITE_ID/releases/RELEASE_ID
sites/SITE_ID/channels/CHANNEL_ID/releases/RELEASE_ID
output: true
- !ruby/object:Api::Type::String
name: release_id
description: The unique identifier for the Release.
output: true
- !ruby/object:Api::Type::Enum
name: type
description: |
The type of the release; indicates what happened to the content of the site. There is no need to specify
`DEPLOY` or `ROLLBACK` type if a `version_name` is provided.
DEPLOY: A version was uploaded to Firebase Hosting and released. Output only.
ROLLBACK: The release points back to a previously deployed version. Output only.
SITE_DISABLE: The release prevents the site from serving content. Firebase Hosting acts as if the site never existed
values:
- :DEPLOY
- :ROLLBACK
- :SITE_DISABLE
- !ruby/object:Api::Type::String
name: message
description: |
The deploy description when the release was created. The value can be up to 512 characters.
- !ruby/object:Api::Resource
name: "Version"
min_version: beta
base_url: sites/{{site_id}}/versions
self_link: sites/{{site_id}}/versions/{{version_id}}
create_url: sites/{{site_id}}/versions
input: true # not updatable
description: |
A `Version` is a configuration which determine how a site is displayed. Static files are not supported at the moment.
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.versions"
parameters:
- !ruby/object:Api::Type::String
name: site_id
description: |
Required. The ID of the site in which to create this Version.
input: true
required: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The fully-qualified resource name for the version, in the format:
sites/SITE_ID/versions/VERSION_ID
output: true
- !ruby/object:Api::Type::String
name: version_id
description: The ID for the version as in sites/SITE_ID/versions/VERSION_ID
output: true
- !ruby/object:Api::Type::NestedObject
name: config
description: The configuration for the behavior of the site. This configuration exists in the `firebase.json` file.
properties:
- !ruby/object:Api::Type::Array
name: rewrites
description: |
An array of objects (called rewrite rules), where each rule specifies a URL pattern that, if matched to the
request URL path, triggers Hosting to respond as if the service were given the specified destination URL.
item_type: !ruby/object:Api::Type::NestedObject
description: |
A Rewrite specifies a URL pattern that, if matched to the request URL path, triggers Hosting to respond as
if the service were given the specified destination URL.
properties:
- !ruby/object:Api::Type::String
name: glob
description: The user-supplied glob to match against the request URL path.
exactly_one_of:
- glob
- regex
- !ruby/object:Api::Type::String
name: regex
description: The user-supplied RE2 regular expression to match against the request URL path.
exactly_one_of:
- glob
- regex
- !ruby/object:Api::Type::String
name: function
description: The function to proxy requests to. Must match the exported function name exactly.
exactly_one_of:
- function
- run
- !ruby/object:Api::Type::NestedObject
name: run
description: The request will be forwarded to Cloud Run.
exactly_one_of:
- function
- run
properties:
- !ruby/object:Api::Type::String
name: serviceId
description: User-defined ID of the Cloud Run service.
required: true
- !ruby/object:Api::Type::String
name: region
description: Optional. User-provided region where the Cloud Run service is hosted. Defaults to `us-central1` if not supplied.
- !ruby/object:Api::Type::Array
name: redirects
description: |
An array of objects (called redirect rules), where each rule specifies a URL pattern that, if matched to the request URL path,
triggers Hosting to respond with a redirect to the specified destination path.
item_type: !ruby/object:Api::Type::NestedObject
description: |
A Redirect specifies a URL pattern that, if matched to the request URL path, triggers Hosting to
respond with a redirect to the specified destination path.
properties:
- !ruby/object:Api::Type::String
name: glob
description: The user-supplied glob to match against the request URL path.
exactly_one_of:
- glob
- regex
- !ruby/object:Api::Type::String
name: regex
description: The user-supplied RE2 regular expression to match against the request URL path.
exactly_one_of:
- glob
- regex
- !ruby/object:Api::Type::Integer
name: statusCode
required: true
description: The status HTTP code to return in the response. It must be a valid 3xx status code.
- !ruby/object:Api::Type::String
name: location
required: true
description: |
The value to put in the HTTP location header of the response.
The location can contain capture group values from the pattern using a : prefix to identify
the segment and an optional * to capture the rest of the URL. For example:
```hcl
redirects {
glob = "/:capture*"
status_code = 302
location = "https://example.com/foo/:capture"
}
```
83 changes: 83 additions & 0 deletions mmv1/products/firebasehosting/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,89 @@ overrides: !ruby/object:Overrides::ResourceOverrides
channel_id: channel-full
test_env_vars:
project_id: :PROJECT_NAME
Release: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: [
'sites/{{site_id}}/releases/{{release_id}}',
'sites/{{site_id}}/channels/{{channel_id}}/releases/{{release_id}}',
'{{site_id}}/{{release_id}}',
'{{site_id}}/{{channel_id}}/{{release_id}}'
]
skip_delete: true # can't delete a release
skip_sweeper: true # can't delete a release
examples:
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_release_in_site"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-id
test_env_vars:
project_id: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_release_in_channel"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-with-channel
channel_id: channel-id
test_env_vars:
project_id: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_release_disable"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-id
test_env_vars:
project_id: :PROJECT_NAME
properties:
release_id: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true # not a field on the resource
type: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true # type may be DEPLOY or ROLLBACK depending on the version
custom_code: !ruby/object:Provider::Terraform::CustomCode
decoder: templates/terraform/decoders/firebasehosting_release.go.erb
post_create: templates/terraform/post_create/firebasehosting_release.erb
Version: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ['sites/{{site_id}}/versions/{{version_id}}', '{{site_id}}/{{version_id}}']
skip_delete: true # can't delete a version
skip_sweeper: true # can't delete a version
examples:
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_version_redirect"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-id
test_env_vars:
project_id: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_version_cloud_run"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-id
cloud_run_service_id: cloud-run-service-via-hosting
test_env_vars:
project_id: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "firebasehosting_version_cloud_functions"
min_version: "beta"
primary_resource_id: "default"
vars:
site_id: site-id
cloud_function_id: cloud-function-via-hosting
zip_path: "function-source.zip"
test_env_vars:
project_id: :PROJECT_NAME
test_vars_overrides:
zip_path: "\"./test-fixtures/cloudfunctions2/function-source.zip\""
properties:
version_id: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true # not a field on the resource
custom_code: !ruby/object:Provider::Terraform::CustomCode
decoder: templates/terraform/decoders/firebasehosting_version.go.erb
post_create: templates/terraform/post_create/firebasehosting_version_immediate_finalize.erb
# 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,5 @@
if err := d.Set("release_id", GetResourceNameFromSelfLink(res["name"].(string))); err != nil {
return nil, err
}

return res, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if err := d.Set("version_id", GetResourceNameFromSelfLink(res["name"].(string))); err != nil {
return nil, err
}

return res, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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_release" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
type = "SITE_DISABLE"
message = "Take down site"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
redirects {
glob = "/google/**"
status_code = 302
location = "https://www.google.com"
}
}
}

resource "google_firebase_hosting_channel" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = "<%= ctx[:vars]['channel_id'] %>"
}

resource "google_firebase_hosting_release" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
channel_id = google_firebase_hosting_channel.default.channel_id
version_name = google_firebase_hosting_version.default.name
message = "Test release in channel"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
redirects {
glob = "/google/**"
status_code = 302
location = "https://www.google.com"
}
}
}

resource "google_firebase_hosting_release" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
version_name = google_firebase_hosting_version.default.name
message = "Test release"
}
Loading

0 comments on commit 63a2809

Please sign in to comment.