https://github.com/alextanhongpin/terraform-aws
Code structure for Terraform running AWS Modules
https://github.com/alextanhongpin/terraform-aws
aws go hashicorp terraform terraform-modules
Last synced: 2 months ago
JSON representation
Code structure for Terraform running AWS Modules
- Host: GitHub
- URL: https://github.com/alextanhongpin/terraform-aws
- Owner: alextanhongpin
- Created: 2018-03-28T15:43:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T13:54:21.000Z (over 8 years ago)
- Last Synced: 2025-03-24T16:15:18.636Z (over 1 year ago)
- Topics: aws, go, hashicorp, terraform, terraform-modules
- Language: HCL
- Size: 1.02 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Terraform Starter
- [x] Create a single AWS instance
- [ ] Link two instances together
- [ ] Make variables
- [ ] Make outputs
- [ ] Store the data in s3
- [ ] Create modules
## Generic Makefile
```Makefile
init:
terraform init
plan:
terraform plan -var-file=main.tfvars -out=main
apply:
terraform apply -var-file=main.tfvars
destroy:
terraform destroy -var-file=main.tfvars
# import:
# terraform import [specific instance...]
graph:
# If you hit the error: /bin/sh: dot: command not found, install graphviz
# brew install graphviz
terraform graph | dot -Tpng > graph.png
```
## TIPS
### Specify the current version
Always specify the current version in used so that users are aware of it.
```
terraform {
required_version = "> 0.7.0"
}
```
### Define variable type for required variables
```hcl
# Good
variable "load_balancer_type" {
type = "string"
}
# Redundant
variable "idle_timeout" {
type = "string"
default = 60
}
# Redundant
variable "internal" {
type = "string"
default = true
}
```
### Split variables to optional and required section
```
# Required
variable "a" {
type = "string"
}
variable "b" {
type = "list"
}
# Optional
variable "c" {
default = true
}
variable "d" {
default = 10
}
```
## Storing to S3 backend
Unfortunately, when you change the access key or secret, the old state cannot be accessed anymore.
```hcl
/*
* AWS S3
*
* Stores the Terraform state of the resources that has been created in the S3 backend.
**/
terraform {
required_version = ">= 0.11.2"
backend "s3" {
bucket = "YOUR_BUCKET_NAME"
key = "YOUR_FILE_NAME"
region = "ap-southeast-1"
encrypt = true
}
}
```