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

[GCP] | Enforce independent resource provisioning per environment #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 25 additions & 5 deletions examples/gcp_cloud_run/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ locals {
})
}
]
feed_topic_id = var.assets_feed_topic_id != null ? var.assets_feed_topic_id : "ocean-integration-topic"
resource_id_prefix = "${var.integration_identifier}-${var.environment}"
feed_topic_id = coalesce(var.assets_feed_topic_id, "${local.resource_id_prefix}-topic")
assets_feed_id = coalesce(var.assets_feed_id, "${local.resource_id_prefix}-assets-feed")

permissions = var.ocean_integration_service_account_permissions != null ? var.ocean_integration_service_account_permissions : ["cloudasset.assets.exportResource",
"cloudasset.assets.listCloudAssetFeeds",
"cloudasset.assets.listResource",
Expand All @@ -79,8 +82,22 @@ locals {
"pubsub.googleapis.com/Subscription",
"pubsub.googleapis.com/Topic"
]
service_account_id = var.service_account_name != null ? var.service_account_name : "ocean-service-account"
role_id = var.role_name != null ? var.role_name : "OceanIntegrationRole"

service_account_id = coalesce(var.service_account_name, "${local.resource_id_prefix}-service-account")
role_id = coalesce(
var.role_name,
format(
"%sRole",
replace(
title(replace(local.resource_id_prefix, "-", " ")),
" ",
""
)
)
)
cloud_run_service_name = coalesce(var.cloud_run_service_name, "${local.resource_id_prefix}-service")


}
module "port_ocean_authorization" {
source = "../../modules/gcp_helpers/authorization"
Expand All @@ -107,24 +124,27 @@ module "port_ocean_assets_feed" {
source = "../../modules/gcp_helpers/assets_feed"
feed_topic_project = var.gcp_ocean_setup_project
billing_project = var.gcp_ocean_setup_project
assets_feed_id = var.assets_feed_id
assets_feed_id = local.assets_feed_id
projects = var.gcp_included_projects
feed_topic = module.port_ocean_pubsub.ocean_topic_name
organization = var.gcp_organization
asset_types = local.asset_types
depends_on = [module.port_ocean_cloud_run]
integration_identifier = local.resource_id_prefix
excluded_projects = var.gcp_excluded_projects
}
resource "time_sleep" "wait_for_authentication_to_take_affect" {
depends_on = [module.port_ocean_authorization]
create_duration = "180s"
}

module "port_ocean_cloud_run" {
source = "../../modules/gcp_helpers/cloud_run"
cloud_run_service_name = local.cloud_run_service_name
service_account_name = module.port_ocean_authorization.service_account_name
environment_variables = local.envs
project = var.gcp_ocean_setup_project
image = var.gcp_ocean_integration_image
depends_on = [time_sleep.wait_for_authentication_to_take_affect]
location = var.gcp_ocean_integration_cloud_run_location
}
}
11 changes: 10 additions & 1 deletion examples/gcp_cloud_run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ variable "ocean_integration_service_account_permissions" {
type = list(string)
default = null
}
variable "cloud_run_service_name" {
type = string
default = null
}
variable "assets_feed_topic_id" {
type = string
default = null
}
variable "assets_feed_id" {
type = string
default = "ocean-gcp-integration-assets-feed"
default = null
description = "The ID for the Ocean GCP Integration feed"
}
variable "service_account_name" {
Expand Down Expand Up @@ -138,4 +142,9 @@ variable "create_service_account" {
type = bool
description = "Determines whether to create a new service account. Set to `true` to create the service account, or `false` to use as existing service account."
default = true
}
variable "environment" {
type = string
description = "The environment for the integration (e.g., 'stg', 'prod')"
default = "prod"
}