I have a Terraform child module for an Azure Function App. This Function App also implements an Azure Monitor Alert (referenced from another child module) and provisions a set of dedicated Action Groups for each environment, i.e. Dev, Test, Staging and Production.
Each Action Group is provisioned with 3 email recipients and requires the corresponding email addresses to be assigned to the variables bmc_email_address, slack_email_address and teams_email_address respectively, as shown below.
module "action-groups" {
source = "../../../modules/monitoring-alert"
environment = var.environment
slack_email_address = var.slack_email_address
teams_email_address = var.teams_email_address
bmc_email_address = var.bmc_email_address
**[[ variables.tf ]]**
variable "db_connection_string" {
type = string
}
variable "bmc_email_address" {
description = "The bmc_email_address for the current environment"
default = null
}
variable "slack_email_address" {
description = "The slack_email_address for the current environment"
default = "[email protected]" # Value must be set conditionally depending on the current environment, i.e. DEV, TEST, STAGING & PRODUCTION
}
variable "teams_email_address" {
description = "The teams_email_address for the current environment"
default = "[email protected]" # Value must be set conditionally depending on the current environment, i.e. DEV, TEST, STAGING & PRODUCTION
The slack and teams email variables are not nullable, meaning if I fail to set a default value, the my child module terraform plan errors on the missing required variable values. Naturally, I cannot and do not wish to set a default value to these variables, as the value differs across all four environments. I would rather prefer some conditional logic based on the current environment which is all handled by my overarching root module and pipeline stage definition.
Any suggestions or ideas?
@ha36d, following on from your feedback and having implemented your proposed solution by:
- Setting up the
email_by_environmentlocal block. - Updating the 3 email address args for the
action-groupimplementation in the 2nd child module.
I am unfortunately still receiving a Missing required argument error in Terraform as depicted below, as the 2nd child module appears to require default values declared for the two non-nullable email variables, i.e. slack_email_address = var.slack_email_address and
teams_email_address = var.teams_email_address
Any suggestions how to get round this?
