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

Add Terraform #152

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
25 changes: 25 additions & 0 deletions broker/setup_broker/terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Setup broker using Terraform

## Organizational thoughts

1. create .tf files: decide whether to do these per resource or per GCP service
2. create Modules: one per component, plus one for the full broker

## Links

- [Terraform Modules](https://www.terraform.io/language/modules/develop)
- [Terraform - Google Modules](https://github.com/terraform-google-modules)
- [Terraform - Google reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_topic_iam#google_pubsub_topic_iam_member)
- [Terraform - Cloud Functions reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudfunctions_function)

## Create starter files

Have gcloud crawl our project and create some starter files for us.

```bash
dir="broker/setup_broker/terraform/pitt-google-broker-prototype"

gcloud beta resource-config bulk-export --project="${GOOGLE_CLOUD_PROJECT}" \
--resource-format=terraform \
--path="${dir}"
```
17 changes: 17 additions & 0 deletions broker/setup_broker/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "google_pubsub_topic" "exgalac_trans" {
name = "ztf-exgalac_trans-${var.suffix}"
project = var.project
}

resource "google_pubsub_topic_iam_member" "publisher" {
topic = google_pubsub_topic.exgalac_trans.name
role = "projects/sen-pittitops-komprise/roles/pubsub.topics.attachSubscription"
member = "allUsers"
project = google_pubsub_topic.exgalac_trans.project
depends_on = [google_pubsub_topic.exgalac_trans]
}

output "topic_name" {
value = google_pubsub_topic.exgalac_trans.name
description = "Name of the created pub/sub topic"
}
17 changes: 17 additions & 0 deletions broker/setup_broker/terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ------------------------------------------------------------
# BACKEND BLOCK
#
# Bucket must exist before configuring the backend
# ------------------------------------------------------------

terraform {
backend "gcs" {
bucket = "gcs-tf-state-bucket"
prefix = "bucket/dir/prefix/"
}

required_providers {
google = "~> 3.1"
google-beta = "~> 3.1"
}
}
10 changes: 10 additions & 0 deletions broker/setup_broker/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "suffix" {
description = "The pub/sub topic suffix"
type = string
default = "4242"
}

variable "project" {
description = "The project to deploy the pub/sub topic to"
type = string
}
2 changes: 2 additions & 0 deletions broker/setup_broker/terraform/vars.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
suffix = "11111"
project = "sen-pittitops-komprise"