commit
b4b9ea7543
11 changed files with 126 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||
|
|
||||
|
# Created by https://www.gitignore.io/api/terraform |
||||
|
|
||||
|
### Terraform ### |
||||
|
# Local .terraform directories |
||||
|
**/.terraform/* |
||||
|
|
||||
|
# .tfstate files |
||||
|
*.tfstate |
||||
|
*.tfstate.* |
||||
|
|
||||
|
# Crash log files |
||||
|
crash.log |
||||
|
|
||||
|
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most |
||||
|
# .tfvars files are managed as part of configuration and so should be included in |
||||
|
# version control. |
||||
|
# |
||||
|
*.tfvars |
||||
|
|
||||
|
|
||||
|
# End of https://www.gitignore.io/api/terraform |
@ -0,0 +1,10 @@ |
|||||
|
repos: |
||||
|
- repo: git://github.com/antonbabenko/pre-commit-terraform |
||||
|
sha: v1.7.3 |
||||
|
hooks: |
||||
|
- id: terraform_fmt |
||||
|
|
||||
|
- repo: git://github.com/pre-commit/pre-commit-hooks |
||||
|
sha: v1.4.0 |
||||
|
hooks: |
||||
|
- id: check-merge-conflict |
@ -0,0 +1,84 @@ |
|||||
|
# Terraform AWS Autoscaling |
||||
|
|
||||
|
## :triangular_ruler: Naming Convention |
||||
|
|
||||
|
Common variables referenced in naming standards |
||||
|
|
||||
|
| Variable | RegExp | Example | |
||||
|
|:----------------------|:--------------------------------|:------------------------------------------------------------| |
||||
|
| `<availability_zone>` | `[a-z]{2}-[a-z]{1,}-[1-2][a-f]` | `us-east-1a`, `us-west-2c`, `eu-west-1a`, `ap-northeast-1c` | |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
## :triangular_ruler: AWS - Resource Naming Standards |
||||
|
|
||||
|
* ALB |
||||
|
|
||||
|
| AWS Resource | Resource Naming | Comment | Example | |
||||
|
|:--------------------|:-------------------------|:---------------------|:----------------------------------------| |
||||
|
| ALB | `<app_name>-alb-private` | Tag `Tier = private` | `web-api-alb-private` | |
||||
|
| | `<app_name>-alb-public` | Tag `Tier = public` | `web-api-alb-public` | |
||||
|
| ALB Target group | `<app_name>-<protocol>` | | `web-api-alb-http`, `web-api-alb-https` | |
||||
|
| ALB Security Groups | `<app_name>-alb` | | `web-api-alb` | |
||||
|
|
||||
|
|
||||
|
* ASG |
||||
|
|
||||
|
| AWS Resource | Resource Naming | Comment | Example | |
||||
|
|:--------------------|:----------------------------|:--------|:------------------------| |
||||
|
| ASG Security Groups | `<app_name>` | | `web-api` | |
||||
|
| ASG Launch Config | `<app_name>-lc-<timestamp>` | | `web-api-lc-1537774225` | |
||||
|
| ASG Launch Template | `<app_name>-lt-<timestamp>` | | `web-api-lt-1537774225` | |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
## :crystal_ball: Terraform Discovery module |
||||
|
|
||||
|
If you followed the naming conventions listed in [terraform-aws-vpc](https://github.com/Lowess/terraform-aws-vpc) you will find it useful to use this [terraform-aws-discovery](https://github.com/Lowess/terraform-aws-discovery) module. The idea of using a discovery module is to centralize `datasource` usage in a central place and keep the source code DRY. |
||||
|
|
||||
|
Here is an example usage: |
||||
|
|
||||
|
```hcl |
||||
|
module "discovery" { |
||||
|
source = "github.com/Lowess/terraform-aws-discovery" |
||||
|
aws_region = var.aws_region |
||||
|
vpc_name = var.vpc_name |
||||
|
ec2_ami_names = ["<AMI-NAME>"] |
||||
|
ec2_ami_owners = "<TEACHER-ACCOUNT-ID>" |
||||
|
ec2_security_groups = [...] |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
> :point_up: If you do not what to use this module you are free to redefine the datasources you need but keep in mind that you will be rebuilding the wheel :ferris_wheel: |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
## 1. Create an `AWS ALB` |
||||
|
|
||||
|
Let's create an `ALB` and the related resources needed (security groups, listeners and target groups). |
||||
|
|
||||
|
* [aws_lb](https://www.terraform.io/docs/providers/aws/r/lb.html) |
||||
|
* [aws_lb_target_group](https://www.terraform.io/docs/providers/aws/r/lb_target_group.html) |
||||
|
* [aws_lb_listener](https://www.terraform.io/docs/providers/aws/r/lb_listener.html) |
||||
|
* [aws_security_group](https://www.terraform.io/docs/providers/aws/r/security_group.html) |
||||
|
* [aws_security_group_rule](https://www.terraform.io/docs/providers/aws/r/security_group_rule.html) |
||||
|
|
||||
|
 |
||||
|
|
||||
|
## 2. Create the `AWS Autoscaling group` |
||||
|
|
||||
|
* [aws_security_group](https://www.terraform.io/docs/providers/aws/r/security_group.html) |
||||
|
* [aws_security_group_rule](https://www.terraform.io/docs/providers/aws/r/security_group_rule.html) |
||||
|
* [aws_launch_template](https://www.terraform.io/docs/providers/aws/r/launch_template.html) |
||||
|
* [aws_autoscaling_group](https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html) |
||||
|
|
||||
|
 |
||||
|
|
||||
|
## 3. Create policies to make the `AWS Autoscaling group` scale in/out |
||||
|
|
||||
|
* Visit the `Cloudwatch` service and discover what this service does |
||||
|
|
||||
|
> :point_up: Think about what's the best metric to use in order to adjust the size of the Autoscaling group |
||||
|
|
||||
|
* [aws_autoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) |
||||
|
|
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 52 KiB |
@ -0,0 +1,8 @@ |
|||||
|
### Provider definition |
||||
|
|
||||
|
provider "aws" { |
||||
|
region = "${var.aws_region}" |
||||
|
} |
||||
|
|
||||
|
### Module Main |
||||
|
|
@ -0,0 +1 @@ |
|||||
|
|
@ -0,0 +1 @@ |
|||||
|
|
Loading…
Reference in new issue