Skip to content

Commit

Permalink
Terraform 0.12 update (terraform-aws-modules#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Jun 6, 2019
1 parent 8f2cf59 commit 554a057
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 138 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.3
rev: v1.12.0
hooks:
- id: terraform_fmt
- id: terraform_docs
# - id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
rev: v2.2.3
hooks:
- id: check-merge-conflict
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraf
```hcl
module "ec2_cluster" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "1.22.0"
version = "~> 2.0"
name = "my-cluster"
instance_count = 5
Expand All @@ -30,7 +30,7 @@ module "ec2_cluster" {
subnet_id = "subnet-eddcdzz4"
tags = {
Terraform = "true"
Terraform = "true"
Environment = "dev"
}
}
Expand Down
44 changes: 26 additions & 18 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data "aws_vpc" "default" {
}

data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}"
vpc_id = data.aws_vpc.default.id
}

data "aws_ami" "amazon_linux" {
Expand All @@ -37,11 +37,11 @@ data "aws_ami" "amazon_linux" {

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"
version = "~> 3.0"

name = "example"
description = "Security group for example usage with EC2 instance"
vpc_id = "${data.aws_vpc.default.id}"
vpc_id = data.aws_vpc.default.id

ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp"]
Expand All @@ -50,7 +50,7 @@ module "security_group" {

resource "aws_eip" "this" {
vpc = true
instance = "${module.ec2.id[0]}"
instance = module.ec2.id[0]
}

module "ec2" {
Expand All @@ -59,16 +59,23 @@ module "ec2" {
instance_count = 2

name = "example-normal"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "m4.large"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true

root_block_device = [{
volume_type = "gp2"
volume_size = 10
}]
root_block_device = [
{
volume_type = "gp2"
volume_size = 10
},
]

tags = {
"Env" = "Private"
"Location" = "Secret"
}
}

module "ec2_with_t2_unlimited" {
Expand All @@ -77,11 +84,11 @@ module "ec2_with_t2_unlimited" {
instance_count = 1

name = "example-t2-unlimited"
ami = "${data.aws_ami.amazon_linux.id}"
ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
cpu_credits = "unlimited"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
}

Expand All @@ -91,10 +98,11 @@ module "ec2_with_t3_unlimited" {
instance_count = 1

name = "example-t3-unlimited"
ami = "${data.aws_ami.amazon_linux.id}"
ami = data.aws_ami.amazon_linux.id
instance_type = "t3.large"
cpu_credits = "unlimited"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
}

24 changes: 15 additions & 9 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
output "ids" {
description = "List of IDs of instances"
value = "${module.ec2.id}"
value = module.ec2.id
}

output "ids_t2" {
description = "List of IDs of t2-type instances"
value = "${module.ec2_with_t2_unlimited.id}"
value = module.ec2_with_t2_unlimited.id
}

output "public_dns" {
description = "List of public DNS names assigned to the instances"
value = "${module.ec2.public_dns}"
value = module.ec2.public_dns
}

output "vpc_security_group_ids" {
description = "List of VPC security group ids assigned to the instances"
value = "${module.ec2.vpc_security_group_ids}"
value = module.ec2.vpc_security_group_ids
}

output "tags" {
description = "List of tags"
value = "${module.ec2.tags}"
value = module.ec2.tags
}

output "instance_id" {
description = "EC2 instance ID"
value = "${module.ec2.id[0]}"
value = module.ec2.id[0]
}

output "t2_instance_id" {
description = "EC2 instance ID"
value = module.ec2_with_t2_unlimited.id[0]
}

output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}"
value = module.ec2.public_dns[0]
}

output "credit_specification" {
description = "Credit specification of EC2 instance (empty list for not t2 instance types)"
value = "${module.ec2.credit_specification}"
value = module.ec2.credit_specification
}

output "credit_specification_t2_unlimited" {
description = "Credit specification of t2-type EC2 instance"
value = "${module.ec2_with_t2_unlimited.credit_specification}"
value = module.ec2_with_t2_unlimited.credit_specification
}

28 changes: 15 additions & 13 deletions examples/volume-attachment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ data "aws_vpc" "default" {
}

data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}"
vpc_id = data.aws_vpc.default.id
}

data "aws_ami" "amazon_linux" {
most_recent = true

owners = ["amazon"]

filter {
name = "name"

Expand All @@ -39,11 +41,11 @@ data "aws_ami" "amazon_linux" {

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"
version = "~> 3.0"

name = "example"
description = "Security group for example usage with EC2 instance"
vpc_id = "${data.aws_vpc.default.id}"
vpc_id = data.aws_vpc.default.id

ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp"]
Expand All @@ -53,27 +55,27 @@ module "security_group" {
module "ec2" {
source = "../../"

instance_count = "${var.instances_number}"
instance_count = var.instances_number

name = "example-with-ebs"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "m4.large"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
}

resource "aws_volume_attachment" "this_ec2" {
count = "${var.instances_number}"
count = var.instances_number

device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.this.*.id[count.index]}"
instance_id = "${module.ec2.id[count.index]}"
volume_id = aws_ebs_volume.this[count.index].id
instance_id = module.ec2.id[count.index]
}

resource "aws_ebs_volume" "this" {
count = "${var.instances_number}"
count = var.instances_number

availability_zone = "${module.ec2.availability_zone[count.index]}"
availability_zone = module.ec2.availability_zone[count.index]
size = 1
}
7 changes: 4 additions & 3 deletions examples/volume-attachment/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
output "instances_public_ips" {
description = "Public IPs assigned to the EC2 instance"
value = "${module.ec2.public_ip}"
value = module.ec2.public_ip
}

output "ebs_volume_attachment_id" {
description = "The volume ID"
value = "${aws_volume_attachment.this_ec2.*.volume_id}"
value = aws_volume_attachment.this_ec2.*.volume_id
}

output "ebs_volume_attachment_instance_id" {
description = "The instance ID"
value = "${aws_volume_attachment.this_ec2.*.instance_id}"
value = aws_volume_attachment.this_ec2.*.instance_id
}

Loading

0 comments on commit 554a057

Please sign in to comment.