variables.tf
variable "env_name" {
default = "some_client"
}
variable "azure_instance_names" {
default = [
"AD01",
"AD01",
]
}
I', trying to create Public IP for as many instances as specified in azure_instance_names
variable (2 in this case), i have issues with naming this resource, i want to create name by joining env_name
and azure_instance_names
variable. It must be one word, separated by -
, so name should be in env_name-azure_instance_names for example:
Desired output
name=some_client-AD01
some_client-AD02
Actual output:
name=some_client AD01
some_client AD02
main.tf
resource "azurerm_public_ip" "datasourceip" {
count = "${length(var.azure_instance_names)}"
name = "${join("-", list(format("%s %s", var.env_name, element(var.azure_instance_names, count.index))))}"
location = "${azurerm_resource_group.res_group.location}"
resource_group_name = "${azurerm_resource_group.res_group.name}"
allocation_method = "Static"
}
In terraform apply i'm getting:
+ azurerm_public_ip.datasourceip[1]
id: <computed>
allocation_method: "Static"
fqdn: <computed>
idle_timeout_in_minutes: "4"
ip_address: <computed>
ip_version: "IPv4"
location: "westeurope"
name: "some_client AD01"
resource_group_name: "myrg1"
sku: "Basic"
tags.%: <computed>
Because Azure doesn't accept resource name in more than one word i', trying to join "-" to var.env_name, var.azure_instance_names
so resource name should be some_client-AD01
Although i specified join function i', still getting same error:
azurerm_public_ip.datasourceip.1: Error Creating/Updating Public IP "some_client AD01" (Resource Group "myrg1"): network.PublicIPAddressesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidResourceName" Message="Resource name some_client LBA-P-EU2B-AD01 is invalid. The name can be up to 80 characters long. It must begin with a word character, and it must end with a word character or with ''. The name may contain word characters or '.', '-', ''." Details=[]