cal-itp / eligibility-server

Server implementation of the Eligibility Verification API
https://docs.calitp.org/eligibility-server
GNU Affero General Public License v3.0
3 stars 3 forks source link

Update terraform config with agency-specific variables #292

Closed thekaveman closed 10 months ago

thekaveman commented 1 year ago

The following Terraform config files reference MST Courtesy Cards, but should use a variable instead, e.g. ${local.agency_card_name}

So we could have something like:

resource "azurerm_linux_web_app" "main" {
  # name needs to be globally unique and is more specific because it's used in the app URL
- name = "mst-courtesy-cards-eligibility-server-${local.env_name}"
+ name = "${local.agency_card_name}-eligibility-server-${local.env_name}"
  #  etc...
}

app_service.tf

resource "azurerm_linux_web_app" "main" {
  # name needs to be globally unique and is more specific because it's used in the app URL
  name = "mst-courtesy-cards-eligibility-server-${local.env_name}"
  #  etc...
}

environment.tf

data "azurerm_resource_group" "main" {
  name = "courtesy-cards-eligibility-${local.env_name}"
}

front_door.tf

resource "azurerm_cdn_frontdoor_endpoint" "main" {
  # used in the front door URL
  name = "mst-courtesy-cards-eligibility-server-${local.env_name}"
  # ...
}

main.tf

terraform {
  # ...
  backend "azurerm" {
    # needs to match pipeline/azure-pipelines.yml
    resource_group_name  = "courtesy-cards-eligibility-terraform"
    storage_account_name = "courtesycardsterraform"
    # ...
  }
}

roles.tf

resource "azurerm_role_assignment" "velocity_etl" {
  # ...
  principal_id = var.VELOCITY_ETL_APP_OBJECT_ID
  condition = <<EOF
(
 (
  @Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs:path] StringLike 'velocity.csv'
 )
)
EOF
   # ...
}

storage.tf

resource "azurerm_storage_account" "main" {
  # name needs to be unique per subscription
  name = "mstcceligibility${local.env_name}"
 # ...
}

uptime.tf

module "healthcheck" {
  # ...
  name = "mst-courtesy-cards-eligibility-server-${local.env_name}-healthcheck"
}

variables.tf

variable "VELOCITY_ETL_APP_OBJECT_ID" {
  description = "Object ID from the registered application for the Velocity server ETL uploading: https://cloudsight.zendesk.com/hc/en-us/articles/360016785598-Azure-finding-your-service-principal-object-ID"
  type = string
}

init.sh

echo "Setting the subscription for the Azure CLI..."
az account set --subscription="MST IT"
thekaveman commented 10 months ago

Backend configuration in main.tf cannot use variables. Need to figure out how to specify a different backend config per agency (multiple main.tf files in subdirectories per-agency?)

angela-tran commented 10 months ago

Backend configuration in main.tf cannot use variables. Need to figure out how to specify a different backend config per agency (multiple main.tf files in subdirectories per-agency?)

We realized that the pipeline gets its backend resource group and storage account config through the TerraformTask configuration. For local development, we can get our backend config through command-line options.

Therefore, we were able to remove resource group and storage account from being specified in the backend block; see https://github.com/cal-itp/eligibility-server/pull/343/commits/3803ffa222bfa0be8585eeebdc40ee40c13fc402 and https://github.com/cal-itp/eligibility-server/pull/343/commits/8af3d3252eab1b35e78375e94fc44a7760089157