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

Upgrade terraform modules #66

Merged
merged 5 commits into from
Dec 3, 2024
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
2 changes: 1 addition & 1 deletion .profile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
##

egress_proxy=`jq -r ".\"user-provided\"[] | select(.name == \"tfm-egress-proxy-$RAILS_ENV-creds\") | .credentials.uri" <<< $VCAP_SERVICES`
egress_proxy=`jq -r ".\"user-provided\"[] | select(.name == \"tfm-egress-proxy-$RAILS_ENV-creds\") | .credentials.https_uri" <<< $VCAP_SERVICES`
export http_proxy="$egress_proxy"
export https_proxy="$egress_proxy"
55 changes: 38 additions & 17 deletions terraform/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ locals {
cf_space_name = "rahearn"
env = "staging"
app_name = "continuous_monitoring"
allow_ssh = true
}

module "app_space" {
source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=v1.1.0"
source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=migrate-provider"

cf_org_name = local.cf_org_name
cf_space_name = local.cf_space_name
allow_ssh = local.allow_ssh
deployers = [
"0ee91aab-1041-494b-b315-307419a0eeac", # CI/CD deploy user
"7b3128d6-86d4-4906-b0ce-f873d9a55c8a" # rahearn-terraform-local
"0ee91aab-1041-494b-b315-307419a0eeac" # CI/CD deploy user
]
# developers should include any users that will potentially need to run `cf ssh` on the app
developers = ["[email protected]"]
}

module "database" {
source = "github.com/gsa-tts/terraform-cloudgov//database?ref=v1.1.0"
source = "github.com/gsa-tts/terraform-cloudgov//database?ref=migrate-provider"

cf_org_name = local.cf_org_name
cf_space_name = local.cf_space_name
cf_space_id = module.app_space.space_id
name = "${local.app_name}-rds-${local.env}"
rds_plan_name = "micro-psql"
# depends_on line is needed only for initial creation and destruction. It should be commented out for updates to prevent unwanted cascading effects
Expand All @@ -41,29 +41,50 @@ module "database" {
# }

module "egress_space" {
source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=v1.1.0"
source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=migrate-provider"

cf_org_name = local.cf_org_name
cf_space_name = "${local.cf_space_name}-egress"
allow_ssh = local.allow_ssh
# deployers should include any user or service account ID that will deploy the egress proxy
deployers = [
"0ee91aab-1041-494b-b315-307419a0eeac", # CI/CD deploy user
"7b3128d6-86d4-4906-b0ce-f873d9a55c8a" # rahearn-terraform-local
"0ee91aab-1041-494b-b315-307419a0eeac" # CI/CD deploy user
]
developers = ["[email protected]"]
}

module "egress_proxy" {
source = "github.com/gsa-tts/terraform-cloudgov//egress_proxy?ref=v1.1.0"
source = "github.com/gsa-tts/terraform-cloudgov//egress_proxy?ref=migrate-provider"

cf_org_name = local.cf_org_name
cf_space_name = module.egress_space.space_name
client_space = local.cf_space_name
name = "tfm-egress-proxy-${local.env}"
# comment out allowlist if this module is being deployed before the app has ever been deployed
allowlist = {
"${local.app_name}-${local.env}" = ["raw.githubusercontent.com"]
cf_org_name = local.cf_org_name
cf_egress_space = {
id = module.egress_space.space_id
name = module.egress_space.space_name
}
name = "tfm-egress-proxy-${local.env}"
allowlist = ["raw.githubusercontent.com"]
# depends_on line is needed only for initial creation and destruction. It should be commented out for updates to prevent unwanted cascading effects
# depends_on = [module.app_space, module.egress_space]
}

data "cloudfoundry_app" "app" {
org_name = local.cf_org_name
space_name = local.cf_space_name
name = "${local.app_name}-${local.env}"
}

resource "cloudfoundry_network_policy" "egress_policy" {
provider = cloudfoundry-community
policy {
source_app = data.cloudfoundry_app.app.id
destination_app = module.egress_proxy.app_id
port = module.egress_proxy.https_port
}
}

resource "cloudfoundry_service_instance" "egress_proxy_credentials" {
name = "tfm-egress-proxy-${local.env}-creds"
space = module.app_space.space_id
type = "user-provided"
credentials = module.egress_proxy.json_credentials
}
18 changes: 14 additions & 4 deletions terraform/staging/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ terraform {
required_version = "~> 1.0"
required_providers {
cloudfoundry = {
source = "cloudfoundry/cloudfoundry"
version = "1.1.0"
}

cloudfoundry-community = {
source = "cloudfoundry-community/cloudfoundry"
version = "0.53.1"
}
Expand All @@ -16,8 +21,13 @@ terraform {
}

provider "cloudfoundry" {
api_url = "https://api.fr.cloud.gov"
user = var.cf_user
password = var.cf_password
app_logs_max = 30
api_url = "https://api.fr.cloud.gov"
user = var.cf_user
password = var.cf_password
}

provider "cloudfoundry-community" {
api_url = "https://api.fr.cloud.gov"
user = var.cf_user
password = var.cf_password
}
Loading