생성 과정

child module


<aside>

설명


main.tf(S3생성 가정, main.tf가 아닌 s3.tf 등 상관 X)
-------
resource "aws_s3_bucket"(s3 생성을 위한 고정된 label) "testS3"(사용자임의) {
	bucket = var.bucket_name
	=> variables.tf에 있는 값을 사용하겠다고 선언 - var.
}

variable.tf
-----------
variables "bucket_test" {
	description = "bucket name"
  type        = string
  sensitive   = true
  default = "s3_example"
}

</aside>

root module


<aside>

main.tf
-------
module "my_s3" {
	source = "./root/s3"
}

</aside>

module화로 인한 장점


<aside>

설명


  1. root/main.tf와 같이 한 곳에 module로 source 해당 디렉토리를 참조하여 apply, destroy 한 곳에서 가능
  2. child module/output.tf → root/main.tf → child module/variables.tf 구조로 서로 다른 child 디렉토리 간 데이터를 참조 가능하여 재사용성 및 코드 단순화 편리 </aside>