From f8aa9bf38c6bd78fc57052529e4c9c707acabcdb Mon Sep 17 00:00:00 2001 From: rosera Date: Thu, 5 Oct 2023 12:32:19 +0100 Subject: [PATCH] Firebase Project: Initial Version Add: Firebase Project creation --- basics/firebase_project/README.md | 43 ++++++++++++++++ basics/firebase_project/cloudbuild.yaml | 21 ++++++++ basics/firebase_project/example/README.md | 42 ++++++++++++++++ basics/firebase_project/example/install.sh | 49 +++++++++++++++++++ basics/firebase_project/example/main.tf | 13 +++++ basics/firebase_project/example/outputs.tf | 10 ++++ basics/firebase_project/example/runtime.yaml | 2 + .../firebase_project/example/scripts/lab-init | 6 +++ basics/firebase_project/example/variables.tf | 12 +++++ basics/firebase_project/stable/main.tf | 19 +++++++ basics/firebase_project/stable/outputs.tf | 15 ++++++ basics/firebase_project/stable/runtime.yaml | 2 + basics/firebase_project/stable/test.tfvars | 3 ++ basics/firebase_project/stable/variables.tf | 20 ++++++++ 14 files changed, 257 insertions(+) create mode 100644 basics/firebase_project/README.md create mode 100644 basics/firebase_project/cloudbuild.yaml create mode 100644 basics/firebase_project/example/README.md create mode 100644 basics/firebase_project/example/install.sh create mode 100644 basics/firebase_project/example/main.tf create mode 100644 basics/firebase_project/example/outputs.tf create mode 100644 basics/firebase_project/example/runtime.yaml create mode 100644 basics/firebase_project/example/scripts/lab-init create mode 100644 basics/firebase_project/example/variables.tf create mode 100644 basics/firebase_project/stable/main.tf create mode 100644 basics/firebase_project/stable/outputs.tf create mode 100644 basics/firebase_project/stable/runtime.yaml create mode 100644 basics/firebase_project/stable/test.tfvars create mode 100644 basics/firebase_project/stable/variables.tf diff --git a/basics/firebase_project/README.md b/basics/firebase_project/README.md new file mode 100644 index 0000000..b296d25 --- /dev/null +++ b/basics/firebase_project/README.md @@ -0,0 +1,43 @@ +# Terraform: Firebase Project + +| Channel | Status | +|---------|--------| +| Stable | ![CloudBuild]() | +| Beta | ![CloudBuild]() | + +Create a Firebase Project based on a Terraform configuration + +## Using Input Values + +__NOTE:__ Qwiklabs requires some values to be defined as part of the provisioning process. + +#### Qwiklabs Properties +``` +gcp_project_id = "my-gcp-project" +gcp_region = "us-central1" +gcp_zone = "us-central1-a" +``` + +#### Custom Properties +N/A + +## Example + +View the [example configuration](https://github.com/CloudVLab/terraform-lab-foundation/tree/main/basics/firebase_project/example) to get started. + +## Accessing Output Values + +| Field | Description | +|-------|-------------| +| firebase_project_id | Firebase project identifier | +| firebase_project_number | Firebase project number | + +## Adding a Commit + +Commits to the repository will initiate the automated QA process + +It is highly recommended that modules are tested locally before making a commit. + +## Request a Pull Request + +__DO NOT__ raise a PR on code that does not pass integration tests. diff --git a/basics/firebase_project/cloudbuild.yaml b/basics/firebase_project/cloudbuild.yaml new file mode 100644 index 0000000..073daed --- /dev/null +++ b/basics/firebase_project/cloudbuild.yaml @@ -0,0 +1,21 @@ +steps: +- name: 'hashicorp/terraform:${_PROVIDER_VER}' + args: ['init'] + id: init-terraform + dir: '${_TERRAFORM_DIR}' +- name: 'hashicorp/terraform:${_PROVIDER_VER}' + args: ['validate'] + id: validate-terraform + dir: '${_TERRAFORM_DIR}' +- name: 'hashicorp/terraform:${_PROVIDER_VER}' + args: ['apply', '-var-file=test.tfvars', '-auto-approve'] + id: apply-terraform + dir: '${_TERRAFORM_DIR}' +- name: 'hashicorp/terraform:${_PROVIDER_VER}' + args: ['destroy', '-var-file=test.tfvars', '-auto-approve'] + id: destroy-terraform + dir: '${_TERRAFORM_DIR}' +substitutions: + _PROVIDER_VER: 1.0.1 + _TERRAFORM_DIR: basics/firebase_project/stable +tags: ['terraform-lab-foundation','firebase', 'project'] diff --git a/basics/firebase_project/example/README.md b/basics/firebase_project/example/README.md new file mode 100644 index 0000000..5c9124f --- /dev/null +++ b/basics/firebase_project/example/README.md @@ -0,0 +1,42 @@ +# Terraform: Firebase Project + +## Example + +The example is based on the following hierarchy: +``` +. +├── instructions +│   ├── en.md +│   └── img +├── QL_OWNER +└── qwiklabs.yaml +``` + +## Add the module to the directory + +Add the example Terraform code module to your project + +``` +curl -L https://github.com/CloudVLab/terraform-lab-foundation/raw/main/basics/firebase_project/example/install.sh | bash +``` + +## View the updated directory + +The example is based on the following hierarchy: + +``` +. +├── instructions +│   ├── en.md +│   └── img +├── QL_OWNER +├── qwiklabs.yaml +└── tf + ├── main.tf + ├── outputs.tf + ├── runtime.yaml + └── variables.tf +``` + +__NOTE:__ The Terraform examples assume a configuration sub-directory +named `tf` is present. diff --git a/basics/firebase_project/example/install.sh b/basics/firebase_project/example/install.sh new file mode 100644 index 0000000..acb2536 --- /dev/null +++ b/basics/firebase_project/example/install.sh @@ -0,0 +1,49 @@ +#!/bin/sh +BRANCH="main" +MODULE="firebase_project" +TYPE="basics" +CHANNEL="STABLE" + +# Set the endpoint for the module +if [ "$CHANNEL" = "STABLE" ]; then + ## STABLE Channel + URL="https://github.com/CloudVLab/terraform-lab-foundation/raw/${BRANCH}" +else + ## DEV/BETA Channel + URL="https://github.com/CloudVLab/terraform-lab-foundation/raw/${BRANCH}" +fi + +DIRECTORY="tf" +FILE1="main.tf" +FILE1_URL="${URL}/${TYPE}/${MODULE}/example/main.tf" +FILE2="outputs.tf" +FILE2_URL="${URL}/${TYPE}/${MODULE}/example/outputs.tf" +FILE3="runtime.yaml" +FILE3_URL="${URL}/${TYPE}/${MODULE}/example/runtime.yaml" +FILE4="variables.tf" +FILE4_URL="${URL}/${TYPE}/${MODULE}/example/variables.tf" + +# Create TF directory if not present +if [ ! -d $DIRECTORY ]; then + mkdir $DIRECTORY +fi + +# Download if the file does not exist +if [ ! -f $DIRECTORY/$FILE1 ]; then +curl -L $FILE1_URL -o "$DIRECTORY/$FILE1" +fi + +# Download if the file does not exist +if [ ! -f $DIRECTORY/$FILE2 ]; then +curl -L $FILE2_URL -o "$DIRECTORY/$FILE2" +fi + +# Download if the file does not exist +if [ ! -f $DIRECTORY/$FILE3 ]; then +curl -L $FILE3_URL -o "$DIRECTORY/$FILE3" +fi + +# Download if the file does not exist +if [ ! -f $DIRECTORY/$FILE4 ]; then +curl -L $FILE4_URL -o "$DIRECTORY/$FILE4" +fi diff --git a/basics/firebase_project/example/main.tf b/basics/firebase_project/example/main.tf new file mode 100644 index 0000000..1ca90d0 --- /dev/null +++ b/basics/firebase_project/example/main.tf @@ -0,0 +1,13 @@ +# Firebase: Project +# Local: modules/[channel] +# Remote: github.com://CloudVLab/terraform-lab-foundation//[module]/[channel] + +# Module: Google Compute Engine +module "la_firebase_project" { + source = "github.com/CloudVLab/terraform-lab-foundation//basics/firebase_project/stable" + + # Pass values to the module + gcp_project_id = var.gcp_project_id + gcp_region = var.gcp_region + gcp_zone = var.gcp_zone +} diff --git a/basics/firebase_project/example/outputs.tf b/basics/firebase_project/example/outputs.tf new file mode 100644 index 0000000..25e4cbf --- /dev/null +++ b/basics/firebase_project/example/outputs.tf @@ -0,0 +1,10 @@ +## Expose Firebase Project properties + +# Terraform Output values +output "firebase_project_id" { + value = module.la_firebase_project.firebase_project_id +} + +output "firebase_project_number" { + value = module.la_firebase_project.firebase_project_number +} diff --git a/basics/firebase_project/example/runtime.yaml b/basics/firebase_project/example/runtime.yaml new file mode 100644 index 0000000..93b5feb --- /dev/null +++ b/basics/firebase_project/example/runtime.yaml @@ -0,0 +1,2 @@ +runtime: terraform +version: 1.0.1 diff --git a/basics/firebase_project/example/scripts/lab-init b/basics/firebase_project/example/scripts/lab-init new file mode 100644 index 0000000..f432c0a --- /dev/null +++ b/basics/firebase_project/example/scripts/lab-init @@ -0,0 +1,6 @@ +#!/bin/sh +# Mandatory Prefix +echo "STARTUP-SCRIPT START" +echo "DO_SOMETHING_HERE" +# Mandatory Postfix +echo "STARTUP-SCRIPT END" diff --git a/basics/firebase_project/example/variables.tf b/basics/firebase_project/example/variables.tf new file mode 100644 index 0000000..757edba --- /dev/null +++ b/basics/firebase_project/example/variables.tf @@ -0,0 +1,12 @@ +# Qwiklabs Mandatory Values +variable "gcp_project_id" { + type = string +} + +variable "gcp_region" { + type = string +} + +variable "gcp_zone" { + type = string +} diff --git a/basics/firebase_project/stable/main.tf b/basics/firebase_project/stable/main.tf new file mode 100644 index 0000000..dbc5a61 --- /dev/null +++ b/basics/firebase_project/stable/main.tf @@ -0,0 +1,19 @@ +# Module: GoogleAPIs +module "la_api_batch" { + source = "github.com/CloudVLab/terraform-lab-foundation//basics/api_service/dev" + + # Pass values to the module + gcp_project_id = var.gcp_project_id + gcp_region = var.gcp_region + gcp_zone = var.gcp_zone + + # Enable Google API(s) + api_services = [ "firebase.googleapis.com" ] +} + +# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/firebase_project.html +resource "google_firebase_project" "default" { + provider = google-beta + project = var.gcp_project_id + depends_on = [ module.la_api_batch ] +} diff --git a/basics/firebase_project/stable/outputs.tf b/basics/firebase_project/stable/outputs.tf new file mode 100644 index 0000000..7207c59 --- /dev/null +++ b/basics/firebase_project/stable/outputs.tf @@ -0,0 +1,15 @@ +## -------------------------------------------------------------- +## Custom variable definitions +## -------------------------------------------------------------- + +## Firebase Project Configuration + + output "firebase_project_id" { + value = "${google_firebase_project.default.project}" + description = "Firebase Project identifier." + } + + output "firebase_project_number" { + value = "${google_firebase_project.default.project_number}" + description = "Firebase Project number." + } diff --git a/basics/firebase_project/stable/runtime.yaml b/basics/firebase_project/stable/runtime.yaml new file mode 100644 index 0000000..93b5feb --- /dev/null +++ b/basics/firebase_project/stable/runtime.yaml @@ -0,0 +1,2 @@ +runtime: terraform +version: 1.0.1 diff --git a/basics/firebase_project/stable/test.tfvars b/basics/firebase_project/stable/test.tfvars new file mode 100644 index 0000000..ffb8348 --- /dev/null +++ b/basics/firebase_project/stable/test.tfvars @@ -0,0 +1,3 @@ +gcp_project_id = "qwiklabs-resources" +gcp_region = "us-central1" +gcp_zone = "us-central1-a" diff --git a/basics/firebase_project/stable/variables.tf b/basics/firebase_project/stable/variables.tf new file mode 100644 index 0000000..7863a7e --- /dev/null +++ b/basics/firebase_project/stable/variables.tf @@ -0,0 +1,20 @@ +## -------------------------------------------------------------- +## Mandatory variable definitions +## -------------------------------------------------------------- + +variable "gcp_project_id" { + type = string + description = "The GCP project ID to create resources in." +} + +# Default value passed in +variable "gcp_region" { + type = string + description = "Region to create resources in." +} + +# Default value passed in +variable "gcp_zone" { + type = string + description = "Zone to create resources in." +}