第 10 章:建立 Terraform 模組
建立組態檔
建立 main.tf
- 使用
module
區塊載入模組 - 這次的
source
填入自製模組的相對路徑 - 給一個獨一無二的
bucket_name
terraform configuration
provider "aws" {
region = "ap-northeast-1"
}
module "website_bucket" {
source = "./modules/static-s3-bucket"
bucket_name = "<YOUR BUCKET NAME>"
tags = {
Terraform = "true"
Environment = "dev"
}
}
outputs.tf
output "website_bucket_arn" {
description = "ARN of the bucket"
value = module.website_bucket.arn
}
output "website_bucket_name" {
description = "Name (id) of the bucket"
value = module.website_bucket.name
}
output "website_endpoint" {
description = "Domain name of the bucket"
value = module.website_bucket.website_endpoint
}
tree folder
$ tree
.
├── main.tf
├── modules
│ └── static-s3-bucket
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── outputs.tf
└── www
├── error.html
└── index.html
www
資料夾是我們另外準備要放到 s3 上測試用的網頁檔,你可以準備自己想要的檔案。