Hi Team,
I am using the following code to create organization on terraform cloud and create VCS provider for each mentioned organization with their Github Org, and i wanted to take the name of varialbe from a given yml file and use that variable inside the child module, i tried the below but getting the following error, can you please help me to resolve this issue.
Code:
terraform {
required_version = “~> 1.0”
required_providers {
tfe = {
version = “~> 0.27.0”
}
}
}
variable “tfe_dev_token” {}
variable “TESTABCD” {}
variable “TEST1ABCD” {}
locals {
rawdata = yamldecode(file(“meta.yml”))
}
provider “tfe” {
alias = “dev”
hostname = “*******”
token = var.tfe_dev_token
}
module “myorg” {
source = “./modules/myorg/”
providers = { tfe = tfe.dev }
for_each = { for k,v in local.rawdata.organization : k => v }
orgame = each.value.name
owner_email = each.value.contact
my_gh_token = var."${each.value.gh_var}"
}
my sample yml file:
organizations:
- name: “TESTABCD”
contact: “abc.def@example.com”
gh_var: “TESTABCD” - name: “TEST1ABCD”
contact: “abc.def@example.com”
gh_var: “TEST1ABCD”
ERROR:
Error: Invalid attribute name
on main.tf line 31, in module "myorg":
31: my_gh_token = var."${each.value.gh_var}"
An attribute name is required after a dot.