diff --git a/INDEX.md b/INDEX.md index 88021edf..bc1b41e8 100644 --- a/INDEX.md +++ b/INDEX.md @@ -2,6 +2,7 @@ | Feature | Links/Related Features | | ------------- |:-------------:| +| `aws_autoscaling_group` | [aws](aws/aws_autoscaling_group)

[simple](aws/aws_autoscaling_group/simple)

[launch_configuration](aws/aws_autoscaling_group/launch_configuration) | | `aws_docdb_cluster` | [aws](aws/aws_docdb_cluster)

[simple](aws/aws_docdb_cluster/simple) | | `aws_db_cluster_snapshot` | [aws](aws/aws_db_cluster_snapshot)

[simple](aws/aws_db_cluster_snapshot/simple) | | `aws_db_instance` | [aws](aws/aws_db_instance)

[simple](aws/aws_db_instance/simple)

[postgres](aws/aws_db_instance/postgres)

[restore_db_from_snapshot](aws/aws_db_instance/restore_db_from_snapshot)

[db_snapshot](aws/aws_db_instance/db_snapshot) | diff --git a/aws/aws_autoscaling_group/launch_configuration/destroy.sh b/aws/aws_autoscaling_group/launch_configuration/destroy.sh new file mode 100755 index 00000000..0f65744a --- /dev/null +++ b/aws/aws_autoscaling_group/launch_configuration/destroy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/destroy.sh aws diff --git a/aws/aws_autoscaling_group/launch_configuration/main.tf b/aws/aws_autoscaling_group/launch_configuration/main.tf new file mode 100644 index 00000000..3e35e486 --- /dev/null +++ b/aws/aws_autoscaling_group/launch_configuration/main.tf @@ -0,0 +1,82 @@ + +# Summary: Create a simple Autoscaling Group + +# Documentation: https://www.terraform.io/docs/language/settings/index.html +terraform { + required_version = ">= 1.0.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.38" + } + } +} + +# Documentation: https://www.terraform.io/docs/language/providers/requirements.html +provider "aws" { + region = "us-east-1" + profile = "terraform-examples" + default_tags { + tags = { + cs_terraform_examples = "aws_autoscaling_group/launch_configuration" + } + } +} + + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc +data "aws_vpc" "changeme_default_aws_vpc" { + default = true +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids +data "aws_subnet_ids" "changeme_aws_subnet_ids" { + vpc_id = data.aws_vpc.changeme_default_aws_vpc.id +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami +# Explanation: Get most_recent version of Ubuntu Image +data "aws_ami" "changeme_aws_ami_lc" { + most_recent = true + + # Explanation: Canonical now publishes official Ubuntu images on the Amazon cloud. + # Check supported versions here : https://uec-images.ubuntu.com/locator/ + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + # Explanation: There are different Public providers (owners), like Canonical, AWS and others . Check here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html + # Some examples of owners: 099720109477 - Canonical and 679593333241 - AWS + owners = ["099720109477"] +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/launch_configuration +resource "aws_launch_configuration" "changeme_aws_launch_configuration" { + name_prefix = "changeme-" + image_id = data.aws_ami.changeme_aws_ami_lc.id + instance_type = "t2.micro" + + lifecycle { + create_before_destroy = true + } +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group +resource "aws_autoscaling_group" "changeme_aws_autoscaling_group_lc" { + name = "changeme-aws-autoscaling-group" + launch_configuration = aws_launch_configuration.changeme_aws_launch_configuration.name + min_size = 1 + max_size = 2 + vpc_zone_identifier = data.aws_subnet_ids.changeme_aws_subnet_ids.ids + + lifecycle { + create_before_destroy = true + } +} + diff --git a/aws/aws_autoscaling_group/launch_configuration/run.sh b/aws/aws_autoscaling_group/launch_configuration/run.sh new file mode 100755 index 00000000..b84d2277 --- /dev/null +++ b/aws/aws_autoscaling_group/launch_configuration/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/apply.sh aws diff --git a/aws/aws_autoscaling_group/simple/destroy.sh b/aws/aws_autoscaling_group/simple/destroy.sh new file mode 100755 index 00000000..0f65744a --- /dev/null +++ b/aws/aws_autoscaling_group/simple/destroy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/destroy.sh aws diff --git a/aws/aws_autoscaling_group/simple/main.tf b/aws/aws_autoscaling_group/simple/main.tf new file mode 100644 index 00000000..38092608 --- /dev/null +++ b/aws/aws_autoscaling_group/simple/main.tf @@ -0,0 +1,67 @@ + + +# Summary: Create a simple Autoscaling Group + +# Documentation: https://www.terraform.io/docs/language/settings/index.html +terraform { + required_version = ">= 1.0.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.38" + } + } +} + +# Documentation: https://www.terraform.io/docs/language/providers/requirements.html +provider "aws" { + region = "us-east-1" + profile = "terraform-examples" + default_tags { + tags = { + cs_terraform_examples = "aws_autoscaling_group/simple" + } + } +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami +# Explanation: Get most_recent version of Ubuntu Image +data "aws_ami" "changeme_aws_ami_simple" { + most_recent = true + + # Explanation: Canonical now publishes official Ubuntu images on the Amazon cloud. + # Check supported versions here : https://uec-images.ubuntu.com/locator/ + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + # Explanation: There are different Public providers (owners), like Canonical, AWS and others . Check here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html + # Some examples of owners: 099720109477 - Canonical and 679593333241 - AWS + owners = ["099720109477"] +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template +resource "aws_launch_template" "changeme_aws_launch_template" { + name_prefix = "changeme-aws-launch-template" + image_id = data.aws_ami.changeme_aws_ami_simple.id + instance_type = "t2.micro" +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group +resource "aws_autoscaling_group" "changeme_aws_autoscaling_group_simple" { + availability_zones = ["us-east-1a"] + desired_capacity = 1 + max_size = 2 + min_size = 1 + + launch_template { + id = aws_launch_template.changeme_aws_launch_template.id + version = "$Latest" + } +} \ No newline at end of file diff --git a/aws/aws_autoscaling_group/simple/run.sh b/aws/aws_autoscaling_group/simple/run.sh new file mode 100755 index 00000000..b84d2277 --- /dev/null +++ b/aws/aws_autoscaling_group/simple/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/apply.sh aws