Can a resource block in the sandbox main.tf call a modules variables and locals?
Basic idea. Have templates created in the modules side and have all the resources I want to create in the environments main.tf
New to terraform and programming
I get this error when running plan to see if it will work
│ Error: Reference to undeclared local value
│
│ on main.tf line 41, in resource "aws_instance" "ami":
│ 41: for_each = { "ami" = local.basic_ami_config }
│
│ A local value with the name "basic_ami_config" has not been declared.
Don’t mind the naming scheme. Things need to be cleaned up
Directory path
Project
-Environment
–Sandbox
—locals.tf
—variables.tf
-Modules
–S3
—locals.tf
—variables.tf
project/environment/sandbox/main.tf
resource "aws_instance" "ami" {
for_each = { "ami" = local.basic_ami_config }
ami = each.value.ami
instance_type = each.value.instance_type
/* subnet_id = each.value.subnet_id
security_groups = each.value.security_groups
associate_public_ip_address = each.value.associate_public_ip_address
key_name = each.value.key_name
*/
}
project/modules/s3/locals.tf
locals {
basic_ami_config = {
ami = var.basic_AMI
instance_type = var.basic_instance_type
/* subnet_id = var.subnet_id
security_groups = var.security_groups
associate_public_ip_address =
key_name = var.key_pair_name
*/
name = local.basic_ami
tags = local.tag
}
}