When you declare modules as follows in ./main.tf:
module "networking" {
source = "./modules/networking"
}
module "security" {
source = "./modules/security"
}
The references to module.networking and module.security are only in scope for local variables, resources, data sources, outputs, and expressions in TF files in the same directory (./*.tf in this case).
Since ./modules/security/security.tf is notin the same directory as ./main.tf, it cannot make reference to module.networking as you are trying here.
A simple fix is to supply vpcid as an input variable to the security module and get its value from module.networking.vpcid:
module "networking" {
source = "./modules/networking"
}
module "security" {
source = "./modules/security"
vpcid = module.networking.vpcid
}
For this to work you need to modify ./modules/security/variables.tf to declare vpcid as an input variable:
variable "vpcid" {
description = "ID of the VPC in which security resources are deployed"
type = string
}
And change the reference in ./modules/security/security.tf:
resource "aws_security_group" "Web-sg" {
// ...
vpc_id = var.vpcid
// ...
}
'♻ Terraform(테라폼) > Module-EC2' 카테고리의 다른 글
Terraform을 활용한 EC2 인스턴스 생성 및 아파치 웹서버 설치 (0) | 2023.03.02 |
---|