Terraform common variable usage in modules -


i writing terraform script create asg on aws. tried create terraform module have more reusable code. problem when want use variable common-variable.tfvars on module tf files, keeps saying undefined , need declared. way, module less reuseable .

here example

root | |___project 1 |     |_____ main.tf |     |_____ common-variable.tfvars | |___ modules       |       |_____ a-module                  |______ main.tf 

so inside project 1 common-variable.tfvars, looks this

variable "a" {      description = "a variable"     default = "a"  }  variable "b" {      description = "a variable"     default = "b"  } 

inside a-module / main.tf looks

variable "name" {}  resource "aws_autoscaling_group" "asg-1" {     name = "${var.a}"     ... } 

when terraform init, says

resource 'aws_autoscaling_group.asg-1' config: unknown variable  referenced: 'a'. define 'variable' blocks 

any idea how can use common variable within module main .tf?


update

i managed pass terraform init redeclaring variable in each module. however, when run terraform plan, kind of error appears invalid value "common-variable.tfvars" flag -var-file: multiple map declarations not supported variables

wrong tfvars format, should key / value only, such as:

a = "a" b = "b" 

second, check how refer module, should this:

source = "../modules/a-module" 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -