A Terraform module for making static websites
- Intall Terraform
- An AWS account
- Install AWS CLI
- An AWS access key ID / secret access key pair,
Set the access key variables:
export AWS_ACCESS_KEY_ID="xxxxx..."
export AWS_SECRET_ACCESS_KEY="xxxxx..."
- In the directory with your web files, create a
main.tffile calling the module, including a bucket name:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.7.1"
}
module "bot-fly" {
source = "../../bot-fly/terraform" # or github URL
bucket_name = "< xxxxxxx... >" # a unique bucket name
}
- Optionally, create a
outputs.tffile, or, just add this to themain.tffile:
output "website_url" {
description = "Website URL (HTTPS)"
value = module.bot-fly.website_url
}
output "s3_url" {
description = "S3 hosting URL (HTTP)"
value = module.bot-fly.s3_url
}
This code will output the location your web files are deployed to.
- Deploy your files:
terraform initto initialize the directory with hidden files (do not commit them)terraform planto prepare to create AWS resoucesterraform applyand then typeyesto createterraform destroyto undo your creation