Skip to content

Commit

Permalink
Terraform updates and make examples buildable. (#84)
Browse files Browse the repository at this point in the history
* Refactor deprecated null_data_source out
* First round of changes in prep of TF upgrade to 0.13.7
* Update of examples
  • Loading branch information
mdfilio committed May 26, 2022
1 parent 76527a7 commit 1fe00fa
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ workflows:
- test:
filters:
branches:
ignore: master
ignore: master
- check_destruction:
requires:
- test
filters:
branches:
ignore: master
ignore: master
2 changes: 1 addition & 1 deletion .terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.2
0.13.7
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ New variable `ssm_bootstrap_list` was added to allow setting the SSM association

| Name | Version |
|------|---------|
| terraform | >= 0.12 |
| aws | >= 2.1.0 |
| terraform | >= 0.13.7 |
| aws | ~> 3.0 |

## Providers

| Name | Version |
|------|---------|
| aws | >= 2.1.0 |
| null | n/a |
| aws | ~> 3.0 |

## Modules

Expand All @@ -69,24 +68,23 @@ New variable `ssm_bootstrap_list` was added to allow setting the SSM association

| Name |
|------|
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/data-sources/ami) |
| [aws_autoscaling_group](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/autoscaling_group) |
| [aws_autoscaling_notification](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/autoscaling_notification) |
| [aws_autoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/autoscaling_policy) |
| [aws_caller_identity](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/data-sources/caller_identity) |
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/cloudwatch_log_group) |
| [aws_cloudwatch_metric_alarm](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/cloudwatch_metric_alarm) |
| [aws_iam_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/iam_instance_profile) |
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/iam_policy) |
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/data-sources/iam_policy_document) |
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/iam_role) |
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/iam_role_policy_attachment) |
| [aws_launch_configuration](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/launch_configuration) |
| [aws_region](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/data-sources/region) |
| [aws_ssm_association](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/ssm_association) |
| [aws_ssm_document](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/ssm_document) |
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/2.1.0/docs/resources/ssm_parameter) |
| [null_data_source](https://registry.terraform.io/providers/hashicorp/null/latest/docs/data-sources/data_source) |
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/data-sources/ami) |
| [aws_autoscaling_group](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/autoscaling_group) |
| [aws_autoscaling_notification](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/autoscaling_notification) |
| [aws_autoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/autoscaling_policy) |
| [aws_caller_identity](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/data-sources/caller_identity) |
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/cloudwatch_log_group) |
| [aws_cloudwatch_metric_alarm](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/cloudwatch_metric_alarm) |
| [aws_iam_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/iam_instance_profile) |
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/iam_policy) |
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/data-sources/iam_policy_document) |
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/iam_role) |
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/iam_role_policy_attachment) |
| [aws_launch_configuration](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/launch_configuration) |
| [aws_region](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/data-sources/region) |
| [aws_ssm_association](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/ssm_association) |
| [aws_ssm_document](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/ssm_document) |
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/3.0/docs/resources/ssm_parameter) |

## Inputs

Expand Down
62 changes: 49 additions & 13 deletions examples/basic_usage.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13.7"
}

provider "aws" {
version = "~> 2.2"
version = "~> 3.0"
region = "us-west-2"
}

resource "random_string" "name_rstring" {
length = 8
special = false
}

module "vpc" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-vpc_basenetwork?ref=v0.12.1"
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-vpc_basenetwork?ref=v0.12.7"

name = "EC2-ASG-BaseNetwork-Test1"
name = "${random_string.name_rstring.result}-ec2-asg-basenetwork-example"
}

data "aws_region" "current_region" {}
Expand All @@ -25,17 +30,43 @@ resource "aws_sqs_queue" "ec2_asg_test_sqs" {
name = "${random_string.sqs_rstring.result}-my-example-queue"
}

module "sns_sqs" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-sns?ref=v0.12.1"
module "sns" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-sns?ref=v0.12.2"

create_subscription_1 = true
endpoint_1 = aws_sqs_queue.ec2_asg_test_sqs.arn
name = "${random_string.sqs_rstring.result}-ec2-asg-test-topic"
protocol_1 = "sqs"
}


module "clb" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-clb?ref=v0.12.4"

name = "${random_string.name_rstring.result}-ec2-asg-clb-example"
security_groups = [module.vpc.default_sg]
subnets = module.vpc.public_subnets
internal_loadbalancer = false
create_logging_bucket = false
rackspace_managed = false

tags = {
Example = "Example-clb"
}


listeners = [
{
instance_port = 8000
instance_protocol = "HTTP"
lb_port = 80
lb_protocol = "HTTP"
},
]
}

module "ec2_asg" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-ec2_asg//?ref=v0.12.4"
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-ec2_asg?ref=v0.12.23"

asg_count = "2"
asg_wait_for_capacity_timeout = "10m"
Expand Down Expand Up @@ -63,20 +94,18 @@ module "ec2_asg" {
health_check_grace_period = "300"
health_check_type = "EC2"
install_codedeploy_agent = false
instance_role_managed_policy_arn_count = "2"
instance_role_managed_policy_arns = [aws_iam_policy.test_policy_1.arn, aws_iam_policy.test_policy_2.arn]
instance_role_managed_policy_arn_count = "3"
instance_type = "t2.micro"
key_pair = "my_ec2_key_name"
load_balancer_names = [aws_elb.my_elb.name]
name = "my_test_instance"
load_balancer_names = [module.clb.name]
name = "${random_string.name_rstring.result}-ec2-asg-instance-example"
perform_ssm_inventory_tag = "True"
primary_ebs_volume_iops = "0"
primary_ebs_volume_size = "60"
primary_ebs_volume_type = "gp2"
rackspace_managed = true
scaling_max = "2"
scaling_min = "1"
scaling_notification_topic = aws_sns_topic.my_test_sns.arn
scaling_notification_topic = module.sns.topic_arn
secondary_ebs_volume_iops = "0"
secondary_ebs_volume_size = "60"
secondary_ebs_volume_type = "gp2"
Expand All @@ -87,6 +116,13 @@ module "ec2_asg" {
tenancy = "default"
terminated_instances = "30"


instance_role_managed_policy_arns = [
"arn:aws:iam::aws:policy/AmazonEC2FullAccess",
"arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetTaggingRole",
"arn:aws:iam::aws:policy/CloudWatchActionsEC2Access",
]

ssm_bootstrap_list = [
{
action = "aws:runDocument",
Expand Down
84 changes: 58 additions & 26 deletions examples/custom_ami.tf
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13.7"
}

provider "aws" {
version = "~> 3.0"
region = "us-west-2"
}

resource "random_string" "name_rstring" {
length = 8
special = false
}

module "vpc" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-vpc_basenetwork?ref=v0.12.1"
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-vpc_basenetwork?ref=v0.12.7"

name = "EC2-ASG-BaseNetwork-Test1"
name = "${random_string.name_rstring.result}-ec2-asg-basenetwork-example"
}

data "aws_region" "current_region" {}
module "alb" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-alb//?ref=v0.12.10"

data "aws_ami" "my_custom_ami" {
executable_users = ["self"]
most_recent = true
owners = ["self"]
create_logging_bucket = false
http_listeners_count = 1
name = "${random_string.name_rstring.result}-test-alb"
rackspace_managed = false
security_groups = [module.vpc.default_sg]
subnets = module.vpc.public_subnets
target_groups_count = 1
vpc_id = module.vpc.vpc_id

filter {
name = "name"
values = ["MyCustomAMI"]
}
http_listeners = [
{
port = 80
protocol = "HTTP"
},
]

target_groups = [
{
backend_port = 80
backend_protocol = "HTTP"
name = "ExampleTargetGroup"
tagert_type = "alb"

}
]
}

data "aws_ami" "community_ami" {


data "aws_region" "current_region" {}

data "aws_ami" "centos7_marketplace" {
owners = ["aws-marketplace"]
most_recent = true
owners = ["679593333241"]

filter {
name = "name"
values = ["CentOS Linux 7 x86_64 HVM EBS*"]
name = "product-code"
values = ["cvugziknvmxgqna9noibqnnsy"]
}
}

Expand All @@ -46,8 +72,8 @@ resource "aws_sqs_queue" "ec2_asg_test_sqs" {
name = "${random_string.sqs_rstring.result}-my-example-queue"
}

module "sns_sqs" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-sns?ref=v0.12.1"
module "sns" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-sns?ref=v0.12.2"

create_subscription_1 = true
endpoint_1 = aws_sqs_queue.ec2_asg_test_sqs.arn
Expand All @@ -56,7 +82,7 @@ module "sns_sqs" {
}

module "ec2_asg" {
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-ec2_asg//?ref=v0.12.4"
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-ec2_asg?ref=v0.12.23"

asg_count = "2"
asg_wait_for_capacity_timeout = "10m"
Expand All @@ -83,22 +109,20 @@ module "ec2_asg" {
environment = "Development"
health_check_grace_period = "300"
health_check_type = "EC2"
image_id = data.aws_ami.community_ami.ami_id
image_id = data.aws_ami.centos7_marketplace.id
install_codedeploy_agent = false
instance_role_managed_policy_arn_count = "2"
instance_role_managed_policy_arns = [aws_iam_policy.test_policy_1.arn, aws_iam_policy.test_policy_2.arn]
instance_role_managed_policy_arn_count = "3"
instance_type = "t2.micro"
key_pair = "my_ec2_key_name"
load_balancer_names = [aws_elb.my_elb.name]
name = "my_test_instance"
target_group_arns = module.alb.target_group_arns
name = "${random_string.name_rstring.result}-ec2-asg-custom-ami-example"
perform_ssm_inventory_tag = "True"
primary_ebs_volume_iops = "0"
primary_ebs_volume_size = "60"
primary_ebs_volume_type = "gp2"
rackspace_managed = true
scaling_max = "2"
scaling_min = "1"
scaling_notification_topic = aws_sns_topic.my_test_sns.arn
scaling_notification_topic = module.sns.topic_arn
secondary_ebs_volume_iops = "0"
secondary_ebs_volume_size = "60"
secondary_ebs_volume_type = "gp2"
Expand All @@ -109,6 +133,13 @@ module "ec2_asg" {
tenancy = "default"
terminated_instances = "30"

instance_role_managed_policy_arns = [
"arn:aws:iam::aws:policy/AmazonEC2FullAccess",
"arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetTaggingRole",
"arn:aws:iam::aws:policy/CloudWatchActionsEC2Access",
]


ssm_bootstrap_list = [
{
action = "aws:runDocument",
Expand Down Expand Up @@ -142,3 +173,4 @@ module "ec2_asg" {
MyTag3 = "Myvalue3"
}
}

Loading

0 comments on commit 1fe00fa

Please sign in to comment.