Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Project: Initial Version #345

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions basics/firebase_project/README.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions basics/firebase_project/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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']
42 changes: 42 additions & 0 deletions basics/firebase_project/example/README.md
Original file line number Diff line number Diff line change
@@ -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.
49 changes: 49 additions & 0 deletions basics/firebase_project/example/install.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions basics/firebase_project/example/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions basics/firebase_project/example/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions basics/firebase_project/example/runtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime: terraform
version: 1.0.1
6 changes: 6 additions & 0 deletions basics/firebase_project/example/scripts/lab-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Mandatory Prefix
echo "STARTUP-SCRIPT START"
echo "DO_SOMETHING_HERE"
# Mandatory Postfix
echo "STARTUP-SCRIPT END"
12 changes: 12 additions & 0 deletions basics/firebase_project/example/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Qwiklabs Mandatory Values
variable "gcp_project_id" {
type = string
}

variable "gcp_region" {
type = string
}

variable "gcp_zone" {
type = string
}
19 changes: 19 additions & 0 deletions basics/firebase_project/stable/main.tf
Original file line number Diff line number Diff line change
@@ -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 ]
}
15 changes: 15 additions & 0 deletions basics/firebase_project/stable/outputs.tf
Original file line number Diff line number Diff line change
@@ -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."
}
2 changes: 2 additions & 0 deletions basics/firebase_project/stable/runtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime: terraform
version: 1.0.1
3 changes: 3 additions & 0 deletions basics/firebase_project/stable/test.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = "qwiklabs-resources"
gcp_region = "us-central1"
gcp_zone = "us-central1-a"
20 changes: 20 additions & 0 deletions basics/firebase_project/stable/variables.tf
Original file line number Diff line number Diff line change
@@ -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."
}