Skip to content

Instantly share code, notes, and snippets.

@joshuaNjordan85
Created March 18, 2020 14:37
Show Gist options
  • Save joshuaNjordan85/9fa52eed36a38ffaa9aa9dd93a5d3d26 to your computer and use it in GitHub Desktop.
Save joshuaNjordan85/9fa52eed36a38ffaa9aa9dd93a5d3d26 to your computer and use it in GitHub Desktop.
GCP functions deployment example
resource "google_cloudfunctions_function" "list_oacs" {
name = "oacbotlist"
description = "functionality related to listing oacs in the library"
runtime = "nodejs10"
region = "us-east1"
project = var.PROJECT_NAME
service_account_email = var.SERVICE_ACCOUNT_EMAIL
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.ops_functions.name
source_archive_object = google_storage_bucket_object.oacbot_list_archive.name
trigger_http = true
labels = {
type = "http"
service = "oacbot"
lang = "node10"
}
entry_point = "list"
environment_variables = {
PROJECT_NAME = var.PROJECT_NAME
SLACK_TOKEN = var.SLACK_TOKEN
SLACK_CLIENT_ID = var.SLACK_CLIENT_ID
SLACK_CLIENT_SECRET = var.SLACK_CLIENT_SECRET
BUCKET = google_storage_bucket.opportunity_as_code.name
ENV = var.env
}
}
resource "google_cloudfunctions_function" "get_oacs" {
name = "oacbotget"
description = "functionality related to getting oacs in the library"
runtime = "nodejs10"
region = "us-east1"
project = var.PROJECT_NAME
service_account_email = var.SERVICE_ACCOUNT_EMAIL
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.ops_functions.name
source_archive_object = google_storage_bucket_object.oacbot_get_archive.name
trigger_http = true
labels = {
type = "http"
service = "oacbot"
lang = "node10"
}
entry_point = "get"
environment_variables = {
PROJECT_NAME = var.PROJECT_NAME
SLACK_TOKEN = var.SLACK_TOKEN
SLACK_CLIENT_ID = var.SLACK_CLIENT_ID
SLACK_CLIENT_SECRET = var.SLACK_CLIENT_SECRET
BUCKET = google_storage_bucket.opportunity_as_code.name
ENV = var.env
}
}
provider "google" {
project = var.PROJECT_NAME
region = var.region
}
output "list_EP" {
value = google_cloudfunctions_function.list_oacs.https_trigger_url
}
output "get_EP" {
value = google_cloudfunctions_function.get_oacs.https_trigger_url
}
resource "google_storage_bucket" "opportunity_as_code" {
name = "opportunity-as-code"
location = var.region
}
resource "google_storage_bucket" "ops_functions" {
name = "ops-functions"
location = var.region
}
resource "google_storage_bucket_object" "oacbot_list_archive" {
name = "oacbotlist.zip"
bucket = google_storage_bucket.ops_functions.name
source = "${path.module}/oacbotlist.zip"
}
resource "google_storage_bucket_object" "oacbot_get_archive" {
name = "oacbotget.zip"
bucket = google_storage_bucket.ops_functions.name
source = "${path.module}/oacbotget.zip"
}
variable "PROJECT_NAME" {
type = string
description = "what project will host the oacBot"
}
variable "SERVICE_ACCOUNT_EMAIL" {
type = string
description = "the service account to run the function with"
}
variable "SLACK_TOKEN" {
type = string
description = "the slack token used to auth slack api interactions"
}
variable "SLACK_CLIENT_ID" {
type = string
description = "the slack client ID used to auth slack api interactions"
}
variable "SLACK_CLIENT_SECRET" {
type = string
description = "the slack client secret used to auth slack api interactions"
}
variable "env" {
type = string
description = "the environment to deploy into"
default = "DEV"
}
variable "region" {
type = string
default = "us-east1"
description = "what region to deploy the oacBot into"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment