Skip to content

Commit ec41031

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#42)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent cf5266e commit ec41031

24 files changed

+874
-273
lines changed

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Cloud Posse][logo]](https://cpco.io/homepage)
55

6-
# terraform-aws-ec2-instance [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-ec2-instance.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-ec2-instance) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance.svg)](https://github.com/cloudposse/terraform-aws-ec2-instance/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-ec2-instance [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ec2-instance?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1a7dc1e38a04899f12f82b) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance.svg)](https://github.com/cloudposse/terraform-aws-ec2-instance/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform Module for provisioning a general purpose EC2 host.
@@ -48,6 +48,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
4848

4949
## Usage
5050

51+
52+
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
53+
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-ec2-instance/releases).
54+
55+
5156
Note: add `${var.ssh_key_pair}` private key to the `ssh agent`.
5257

5358
Include this repository as a module in your existing terraform code.
@@ -57,14 +62,14 @@ Include this repository as a module in your existing terraform code.
5762
```hcl
5863
module "instance" {
5964
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance.git?ref=master"
60-
ssh_key_pair = "${var.ssh_key_pair}"
61-
instance_type = "${var.instance_type}"
62-
vpc_id = "${var.vpc_id}"
63-
security_groups = ["${var.security_groups}"]
64-
subnet = "${var.subnet}"
65-
name = "${var.name}"
66-
namespace = "${var.namespace}"
67-
stage = "${var.stage}"
65+
ssh_key_pair = var.ssh_key_pair
66+
instance_type = var.instance_type
67+
vpc_id = var.vpc_id
68+
security_groups = var.security_groups
69+
subnet = var.subnet
70+
name = "ec2"
71+
namespace = "eg"
72+
stage = "dev"
6873
}
6974
```
7075

@@ -73,17 +78,17 @@ module "instance" {
7378
```hcl
7479
module "kafka_instance" {
7580
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance.git?ref=master"
76-
ssh_key_pair = "${var.ssh_key_pair}"
77-
vpc_id = "${var.vpc_id}"
78-
security_groups = ["${var.security_groups}"]
79-
subnet = "${var.subnet}"
80-
associate_public_ip_address = "true"
81+
ssh_key_pair = var.ssh_key_pair
82+
vpc_id = var.vpc_id
83+
security_groups = var.security_groups
84+
subnet = var.subnet
85+
associate_public_ip_address = true
8186
name = "kafka"
82-
namespace = "cp"
87+
namespace = "eg"
8388
stage = "dev"
84-
additional_ips_count = "1"
85-
ebs_volume_count = "2"
86-
allowed_ports = ["22", "80", "443"]
89+
additional_ips_count = 1
90+
ebs_volume_count = 2
91+
allowed_ports = [22, 80, 443]
8792
}
8893
```
8994

@@ -106,53 +111,53 @@ Available targets:
106111

107112
| Name | Description | Type | Default | Required |
108113
|------|-------------|:----:|:-----:|:-----:|
109-
| additional_ips_count | Count of additional EIPs | string | `0` | no |
110-
| allowed_ports | List of allowed ingress ports | list | `<list>` | no |
114+
| additional_ips_count | Count of additional EIPs | number | `0` | no |
115+
| allowed_ports | List of allowed ingress ports | list(number) | `<list>` | no |
111116
| ami | The AMI to use for the instance. By default it is the AMI provided by Amazon with Ubuntu 16.04 | string | `` | no |
112117
| ami_owner | Owner of the given AMI (ignored if `ami` unset) | string | `` | no |
113-
| applying_period | The period in seconds over which the specified statistic is applied | string | `60` | no |
114-
| assign_eip_address | Assign an Elastic IP address to the instance | string | `true` | no |
115-
| associate_public_ip_address | Associate a public IP address with the instance | string | `true` | no |
116-
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
118+
| applying_period | The period in seconds over which the specified statistic is applied | number | `60` | no |
119+
| assign_eip_address | Assign an Elastic IP address to the instance | bool | `true` | no |
120+
| associate_public_ip_address | Associate a public IP address with the instance | bool | `true` | no |
121+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
117122
| availability_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | string | `` | no |
118123
| comparison_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold. | string | `GreaterThanOrEqualToThreshold` | no |
119-
| create_default_security_group | Create default Security Group with only Egress traffic allowed | string | `true` | no |
120-
| default_alarm_action | - | string | `action/actions/AWS_EC2.InstanceId.Reboot/1.0` | no |
121-
| delete_on_termination | Whether the volume should be destroyed on instance termination | string | `true` | no |
124+
| create_default_security_group | Create default Security Group with only Egress traffic allowed | bool | `true` | no |
125+
| default_alarm_action | Default alerm action | string | `action/actions/AWS_EC2.InstanceId.Reboot/1.0` | no |
126+
| delete_on_termination | Whether the volume should be destroyed on instance termination | bool | `true` | no |
122127
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
123-
| disable_api_termination | Enable EC2 Instance Termination Protection | string | `false` | no |
124-
| ebs_device_name | Name of the EBS device to mount | list | `<list>` | no |
125-
| ebs_iops | Amount of provisioned IOPS. This must be set with a volume_type of io1 | string | `0` | no |
126-
| ebs_optimized | Launched EC2 instance will be EBS-optimized | string | `false` | no |
127-
| ebs_volume_count | Count of EBS volumes that will be attached to the instance | string | `0` | no |
128-
| ebs_volume_size | Size of the EBS volume in gigabytes | string | `10` | no |
128+
| disable_api_termination | Enable EC2 Instance Termination Protection | bool | `false` | no |
129+
| ebs_device_name | Name of the EBS device to mount | list(string) | `<list>` | no |
130+
| ebs_iops | Amount of provisioned IOPS. This must be set with a volume_type of io1 | number | `0` | no |
131+
| ebs_optimized | Launched EC2 instance will be EBS-optimized | bool | `false` | no |
132+
| ebs_volume_count | Count of EBS volumes that will be attached to the instance | number | `0` | no |
133+
| ebs_volume_size | Size of the EBS volume in gigabytes | number | `10` | no |
129134
| ebs_volume_type | The type of EBS volume. Can be standard, gp2 or io1 | string | `gp2` | no |
130-
| evaluation_periods | The number of periods over which data is compared to the specified threshold. | string | `5` | no |
131-
| instance_enabled | Flag to control the instance creation. Set to false if it is necessary to skip instance creation | string | `true` | no |
135+
| evaluation_periods | The number of periods over which data is compared to the specified threshold. | number | `5` | no |
136+
| instance_enabled | Flag to control the instance creation. Set to false if it is necessary to skip instance creation | bool | `true` | no |
132137
| instance_type | The type of the instance | string | `t2.micro` | no |
133-
| ipv6_address_count | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet | string | `0` | no |
134-
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | list | `<list>` | no |
138+
| ipv6_address_count | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet | number | `0` | no |
139+
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | list(string) | `<list>` | no |
135140
| metric_name | The name for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html | string | `StatusCheckFailed_Instance` | no |
136141
| metric_namespace | The namespace for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html | string | `AWS/EC2` | no |
137-
| metric_threshold | The value against which the specified statistic is compared | string | `1` | no |
138-
| monitoring | Launched EC2 instance will have detailed monitoring enabled | string | `true` | no |
142+
| metric_threshold | The value against which the specified statistic is compared | number | `1` | no |
143+
| monitoring | Launched EC2 instance will have detailed monitoring enabled | bool | `true` | no |
139144
| name | Name (e.g. `bastion` or `db`) | string | - | yes |
140-
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
145+
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | `` | no |
141146
| private_ip | Private IP address to associate with the instance in the VPC | string | `` | no |
142147
| region | AWS Region the instance is launched in | string | `` | no |
143-
| root_iops | Amount of provisioned IOPS. This must be set if root_volume_type is set to `io1` | string | `0` | no |
144-
| root_volume_size | Size of the root volume in gigabytes | string | `10` | no |
148+
| root_iops | Amount of provisioned IOPS. This must be set if root_volume_type is set to `io1` | number | `0` | no |
149+
| root_volume_size | Size of the root volume in gigabytes | number | `10` | no |
145150
| root_volume_type | Type of root volume. Can be standard, gp2 or io1 | string | `gp2` | no |
146-
| security_groups | List of Security Group IDs allowed to connect to the instance | list | `<list>` | no |
147-
| source_dest_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs | string | `true` | no |
151+
| security_groups | List of Security Group IDs allowed to connect to the instance | list(string) | `<list>` | no |
152+
| source_dest_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs | bool | `true` | no |
148153
| ssh_key_pair | SSH key pair to be provisioned on the instance | string | - | yes |
149-
| stage | Stage (e.g. `prod`, `dev`, `staging` | string | - | yes |
154+
| stage | Stage (e.g. `prod`, `dev`, `staging` | string | `` | no |
150155
| statistic_level | The statistic to apply to the alarm's associated metric. Allowed values are: SampleCount, Average, Sum, Minimum, Maximum | string | `Maximum` | no |
151156
| subnet | VPC Subnet ID the instance is launched in | string | - | yes |
152-
| tags | Additional tags | map | `<map>` | no |
157+
| tags | Additional tags | map(string) | `<map>` | no |
153158
| user_data | Instance user data. Do not pass gzip-compressed data via this argument | string | `` | no |
154159
| vpc_id | The ID of the VPC that the instance security group belongs to | string | - | yes |
155-
| welcome_message | - | string | `` | no |
160+
| welcome_message | Welcome message | string | `` | no |
156161

157162
## Outputs
158163

README.yaml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ github_repo: cloudposse/terraform-aws-ec2-instance
3333

3434
# Badges to display
3535
badges:
36-
- name: "Build Status"
37-
image: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance.svg?branch=master"
38-
url: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance"
36+
- name: "Codefresh Build Status"
37+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ec2-instance?type=cf-1"
38+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1a7dc1e38a04899f12f82b"
3939
- name: "Latest Release"
4040
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance.svg"
4141
url: "https://github.com/cloudposse/terraform-aws-ec2-instance/releases/latest"
@@ -44,18 +44,18 @@ badges:
4444
url: "https://slack.cloudposse.com"
4545

4646
related:
47-
- name: "terraform-aws-ec2-ami-backup"
48-
description: "Terraform module for automatic & scheduled AMI creation"
49-
url: "https://github.com/cloudposse/terraform-aws-ec2-ami-backup"
50-
- name: "terraform-aws-ec2-ami-snapshot"
51-
description: "Terraform module to easily generate AMI snapshots to create replica instances"
52-
url: "https://github.com/cloudposse/terraform-aws-ec2-ami-snapshot"
53-
- name: "terraform-aws-ec2-cloudwatch-sns-alarms"
54-
description: "Terraform module that configures CloudWatch SNS alerts for EC2 instances"
55-
url: "https://github.com/cloudposse/terraform-aws-ec2-cloudwatch-sns-alarms"
56-
- name: "terraform-null-label"
57-
description: "Terraform Module to define a consistent naming convention by (namespace, stage, name, [attributes])"
58-
url: "https://github.com/cloudposse/terraform-null-label"
47+
- name: "terraform-aws-ec2-ami-backup"
48+
description: "Terraform module for automatic & scheduled AMI creation"
49+
url: "https://github.com/cloudposse/terraform-aws-ec2-ami-backup"
50+
- name: "terraform-aws-ec2-ami-snapshot"
51+
description: "Terraform module to easily generate AMI snapshots to create replica instances"
52+
url: "https://github.com/cloudposse/terraform-aws-ec2-ami-snapshot"
53+
- name: "terraform-aws-ec2-cloudwatch-sns-alarms"
54+
description: "Terraform module that configures CloudWatch SNS alerts for EC2 instances"
55+
url: "https://github.com/cloudposse/terraform-aws-ec2-cloudwatch-sns-alarms"
56+
- name: "terraform-null-label"
57+
description: "Terraform Module to define a consistent naming convention by (namespace, stage, name, [attributes])"
58+
url: "https://github.com/cloudposse/terraform-null-label"
5959

6060
# Short description of this project
6161
description: |-
@@ -78,14 +78,14 @@ usage: |-
7878
```hcl
7979
module "instance" {
8080
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance.git?ref=master"
81-
ssh_key_pair = "${var.ssh_key_pair}"
82-
instance_type = "${var.instance_type}"
83-
vpc_id = "${var.vpc_id}"
84-
security_groups = ["${var.security_groups}"]
85-
subnet = "${var.subnet}"
86-
name = "${var.name}"
87-
namespace = "${var.namespace}"
88-
stage = "${var.stage}"
81+
ssh_key_pair = var.ssh_key_pair
82+
instance_type = var.instance_type
83+
vpc_id = var.vpc_id
84+
security_groups = var.security_groups
85+
subnet = var.subnet
86+
name = "ec2"
87+
namespace = "eg"
88+
stage = "dev"
8989
}
9090
```
9191
@@ -94,20 +94,20 @@ usage: |-
9494
```hcl
9595
module "kafka_instance" {
9696
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance.git?ref=master"
97-
ssh_key_pair = "${var.ssh_key_pair}"
98-
vpc_id = "${var.vpc_id}"
99-
security_groups = ["${var.security_groups}"]
100-
subnet = "${var.subnet}"
101-
associate_public_ip_address = "true"
97+
ssh_key_pair = var.ssh_key_pair
98+
vpc_id = var.vpc_id
99+
security_groups = var.security_groups
100+
subnet = var.subnet
101+
associate_public_ip_address = true
102102
name = "kafka"
103-
namespace = "cp"
103+
namespace = "eg"
104104
stage = "dev"
105-
additional_ips_count = "1"
106-
ebs_volume_count = "2"
107-
allowed_ports = ["22", "80", "443"]
105+
additional_ips_count = 1
106+
ebs_volume_count = 2
107+
allowed_ports = [22, 80, 443]
108108
}
109109
```
110-
110+
111111
# References
112112
references:
113113
- name: "terraform-aws-ec2-bastion-server"
@@ -131,8 +131,8 @@ contributors:
131131
- name: "Valeriy"
132132
github: "drama17"
133133
- name: "Ivan Pinatti"
134-
github: "ivan-pinatti"
134+
github: "ivan-pinatti"
135135
- name: "Vladimir"
136-
github: "SweetOps"
136+
github: "SweetOps"
137137
- name: "Konstantin B"
138-
github: "comeanother"
138+
github: "comeanother"

cloud_watch_alarm.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# Restart dead or hung instance
22

33
resource "null_resource" "check_alarm_action" {
4-
count = "${local.instance_count}"
4+
count = local.instance_count
55

66
triggers = {
77
action = "arn:aws:swf:${local.region}:${data.aws_caller_identity.default.account_id}:${var.default_alarm_action}"
88
}
99
}
1010

1111
resource "aws_cloudwatch_metric_alarm" "default" {
12-
count = "${local.instance_count}"
13-
alarm_name = "${module.label.id}"
14-
comparison_operator = "${var.comparison_operator}"
15-
evaluation_periods = "${var.evaluation_periods}"
16-
metric_name = "${var.metric_name}"
17-
namespace = "${var.metric_namespace}"
18-
period = "${var.applying_period}"
19-
statistic = "${var.statistic_level}"
20-
threshold = "${var.metric_threshold}"
21-
depends_on = ["null_resource.check_alarm_action"]
12+
count = local.instance_count
13+
alarm_name = module.label.id
14+
comparison_operator = var.comparison_operator
15+
evaluation_periods = var.evaluation_periods
16+
metric_name = var.metric_name
17+
namespace = var.metric_namespace
18+
period = var.applying_period
19+
statistic = var.statistic_level
20+
threshold = var.metric_threshold
21+
depends_on = [null_resource.check_alarm_action]
2222

23-
dimensions {
24-
InstanceId = "${aws_instance.default.id}"
23+
dimensions = {
24+
InstanceId = join("", aws_instance.default.*.id)
2525
}
2626

2727
alarm_actions = [
28-
"${null_resource.check_alarm_action.triggers.action}",
28+
null_resource.check_alarm_action[count.index].triggers.action
2929
]
3030
}

0 commit comments

Comments
 (0)