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

chore: enable gcp apis #116

Merged
merged 2 commits into from
Aug 1, 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
16 changes: 12 additions & 4 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ locals {

// ====== GCP ======

module "gcp_apis" {
source = "./modules/gcp/apis"
apis_to_enable = [
"cloudtasks.googleapis.com"
]
}

module "gcp_iam" {
source = "./modules/gcp/iam"
identity_providers = [
Expand All @@ -24,6 +31,7 @@ module "gcp_iam" {
]
}


// ====== AWS ======

data "aws_region" "current" {}
Expand Down Expand Up @@ -208,10 +216,10 @@ module "azure_rabbitmq_app_registration" {
application_purpose = "rabbitmq-oauth"
# list of roles to create in application - see https://www.rabbitmq.com/oauth2.html#scope-and-tags
app_roles = {
management = "rabbitmq.tag:management"
management = "rabbitmq.tag:management"
administrator = "rabbitmq.tag:administrator"
read_all = "rabbitmq.read:*/*/*"
write_all = "rabbitmq.write:*/*/*"
read_all = "rabbitmq.read:*/*/*"
write_all = "rabbitmq.write:*/*/*"
configure_all = "rabbitmq.configure:*/*/*"
}

Expand Down Expand Up @@ -332,7 +340,7 @@ module "github_secrets" {
value = module.gcp_iam.project_number
},
{
name = "TF_AZURE_RABBIT_API_APPLICATION_ID"
name = "TF_AZURE_RABBIT_API_APPLICATION_ID"
value = module.azure_rabbitmq_app_registration.application_id
},
]
Expand Down
8 changes: 4 additions & 4 deletions terraform/modules/azure/app-registration/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ terraform {
}

locals {
application_name = "${var.unique_project_name}-${var.application_purpose}"
application_name = "${var.unique_project_name}-${var.application_purpose}"
application_identifier = "api://${local.application_name}"
}

Expand Down Expand Up @@ -54,16 +54,16 @@ resource "azuread_application" "oauth2_api" {

resource "azuread_service_principal" "oauth2_api" {
application_id = azuread_application.oauth2_api.application_id
use_existing = true
use_existing = true
}

locals {
# assign each role to each identity requested
roles_to_principals = flatten([
for role,_ in var.app_roles : [
for role, _ in var.app_roles : [
for identity in var.access_identities : {
role_uuid_key = random_uuid.app_roles[role].id
principal_id = identity.principal_id
principal_id = identity.principal_id
}
]
])
Expand Down
13 changes: 13 additions & 0 deletions terraform/modules/gcp/apis/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data "google_project" "project" {}

locals {
// We use maps instead of arrays to have a string index based on the name
// otherwise, changes in the order would recreate the resources
apis = { for i, api in var.apis_to_enable : api => api }
}

resource "google_project_service" "apis" {
for_each = local.apis
project = data.google_project.project.project_id
service = each.key
}
4 changes: 4 additions & 0 deletions terraform/modules/gcp/apis/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "apis_to_enable" {
type = list(string)
description = "Collection of APIs to enable"
}