Skip to content

Commit 27190f9

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#8)
* Convert to TF 0.12 * Convert to TF 0.12 * 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 * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Update `tags` variable
1 parent 2b74c66 commit 27190f9

28 files changed

+1200
-512
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
*.iml
55
**/terraform.tfstate
66
**/terraform.tfstate.backup
7-
**/terraform.tfvars
87
**/*.pem
98
**/*.pub
109

1110
.build-harness
12-
build-harness
11+
build-harness

.travis.yml

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

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2018-2019 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 66 additions & 65 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-ec2-instance-group
1818

1919
# Badges to display
2020
badges:
21-
- name: "Build Status"
22-
image: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance-group.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance-group"
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ec2-instance-group?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d2c103fd17b10438bdd81e2"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance-group.svg"
2626
url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group/releases/latest"
@@ -45,7 +45,7 @@ description: |-
4545
4646
If you only need to provision a single EC2 instance, consider using the [terraform-aws-ec2-instance](https://github.com/cloudposse/terraform-aws-ec2-instance) module instead.
4747
48-
**IMPORTANT** This module by-design does not provision an AutoScaling group. It was designed to provision a discrete number of instances suitable for running stateful services such as databases (E.g. Kafka, Redis, etc).
48+
**IMPORTANT** This module by-design does not provision an AutoScaling group. It was designed to provision a discrete number of instances suitable for running stateful services such as databases (e.g. Kafka, Redis, etc).
4949
5050
5151
Included features:
@@ -66,18 +66,17 @@ usage: |-
6666
```hcl
6767
module "instance" {
6868
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance-group.git?ref=master"
69-
namespace = "cp"
69+
namespace = "eg"
7070
stage = "prod"
7171
name = "app"
7272
ami = "ami-a4dc46db"
7373
ami_owner = "099720109477"
74-
ssh_key_pair = "${var.ssh_key_pair}"
75-
instance_type = "${var.instance_type}"
76-
vpc_id = "${var.vpc_id}"
77-
security_groups = ["${var.security_groups}"]
78-
subnet = "${var.subnet}"
79-
80-
instance_count = "3"
74+
ssh_key_pair = var.ssh_key_pair
75+
instance_type = var.instance_type
76+
vpc_id = var.vpc_id
77+
security_groups = var.security_groups
78+
subnet = var.subnet
79+
instance_count = 3
8180
}
8281
```
8382
@@ -86,21 +85,20 @@ usage: |-
8685
```hcl
8786
module "kafka_instance" {
8887
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance-group.git?ref=master"
89-
namespace = "cp"
88+
namespace = "eg"
9089
stage = "prod"
9190
name = "app"
9291
ami = "ami-a4dc46db"
9392
ami_owner = "099720109477"
94-
ssh_key_pair = "${var.ssh_key_pair}"
95-
vpc_id = "${var.vpc_id}"
96-
security_groups = ["${var.security_groups}"]
97-
subnet = "${var.subnet}"
98-
associate_public_ip_address = "true"
99-
additional_ips_count = "1"
100-
ebs_volume_count = "2"
101-
allowed_ports = ["22", "80", "443"]
102-
103-
instance_count = "3"
93+
ssh_key_pair = var.ssh_key_pair
94+
vpc_id = var.vpc_id
95+
security_groups = var.security_groups
96+
subnet = var.subnet
97+
associate_public_ip_address = true
98+
additional_ips_count = 1
99+
ebs_volume_count = 2
100+
allowed_ports = [22, 80, 443]
101+
instance_count = 3
104102
}
105103
```
106104
@@ -114,11 +112,12 @@ usage: |-
114112
It is necessary to run `terraform get` or `terraform init` to download this module.
115113
116114
Now reference the label when creating an instance (for example):
115+
117116
```hcl
118117
resource "aws_ami_from_instance" "example" {
119-
count = "${length(module.instance.*.id)}"
120-
name = "terraform-example"
121-
source_instance_id = "${element(module.instance.*.id, count.index)}"
118+
count = length(module.instance.*.id)
119+
name = "app"
120+
source_instance_id = element(module.instance.*.id, count.index)
122121
}
123122
```
124123
@@ -139,3 +138,5 @@ contributors:
139138
github: "Jamie-BitFlight"
140139
- name: "Vladimir"
141140
github: "SweetOps"
141+
- name: "Andriy Knysh"
142+
github: "aknysh"

cloud_watch_alarm.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ locals {
55
}
66

77
resource "aws_cloudwatch_metric_alarm" "default" {
8-
count = "${local.instance_count}"
8+
count = local.instance_count
99
alarm_name = "${module.label.id}-${count.index}"
10-
comparison_operator = "${var.comparison_operator}"
11-
evaluation_periods = "${var.evaluation_periods}"
12-
metric_name = "${var.metric_name}"
13-
namespace = "${var.metric_namespace}"
14-
period = "${var.applying_period}"
15-
statistic = "${var.statistic_level}"
16-
threshold = "${var.metric_threshold}"
10+
comparison_operator = var.comparison_operator
11+
evaluation_periods = var.evaluation_periods
12+
metric_name = var.metric_name
13+
namespace = var.metric_namespace
14+
period = var.applying_period
15+
statistic = var.statistic_level
16+
threshold = var.metric_threshold
1717

18-
dimensions {
19-
InstanceId = "${element(sort(aws_instance.default.*.id), count.index)}"
18+
dimensions = {
19+
InstanceId = sort(aws_instance.default.*.id)[count.index]
2020
}
2121

2222
alarm_actions = [
23-
"${local.action}",
23+
local.action
2424
]
2525
}

codefresh/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- make -C test/src

docs/terraform.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,56 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| additional_ips_count | Count of additional EIPs | string | `0` | no |
6-
| allowed_ports | List of allowed ingress ports | list | `<list>` | no |
7-
| ami | The AMI to use for the instance. | string | - | yes |
5+
| additional_ips_count | Count of additional EIPs | number | `0` | no |
6+
| allowed_ports | List of allowed ingress ports | list(number) | `<list>` | no |
7+
| ami | The AMI to use for the instance | string | - | yes |
88
| ami_owner | Owner of the given AMI | string | - | yes |
9-
| applying_period | The period in seconds over which the specified statistic is applied | string | `60` | no |
10-
| assign_eip_address | Assign an Elastic IP address to the instance | string | `true` | no |
11-
| associate_public_ip_address | Associate a public IP address with the instance | string | `true` | no |
12-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
9+
| applying_period | The period in seconds over which the specified statistic is applied | number | `60` | no |
10+
| assign_eip_address | Assign an Elastic IP address to the instance | bool | `true` | no |
11+
| associate_public_ip_address | Associate a public IP address with the instance | bool | `true` | no |
12+
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
1313
| availability_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | string | `` | no |
14-
| comparison_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold. | string | `GreaterThanOrEqualToThreshold` | no |
15-
| create_default_security_group | Create default Security Group with only Egress traffic allowed | string | `true` | no |
16-
| default_alarm_action | - | string | `action/actions/AWS_EC2.InstanceId.Reboot/1.0` | no |
17-
| delete_on_termination | Whether the volume should be destroyed on instance termination | string | `true` | no |
18-
| delimiter | - | string | `-` | no |
19-
| disable_api_termination | Enable EC2 Instance Termination Protection | string | `false` | no |
20-
| ebs_device_names | Name of the EBS device to mount | list | `<list>` | no |
21-
| ebs_iops | Amount of provisioned IOPS. This must be set with a volume_type of io1 | string | `0` | no |
22-
| ebs_optimized | Launched EC2 instance will be EBS-optimized | string | `false` | no |
23-
| ebs_volume_count | Count of EBS volumes that will be attached to the instance | string | `0` | no |
24-
| ebs_volume_size | Size of the EBS volume in gigabytes | string | `10` | no |
14+
| comparison_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold | string | `GreaterThanOrEqualToThreshold` | no |
15+
| create_default_security_group | Create default Security Group with only Egress traffic allowed | bool | `true` | no |
16+
| default_alarm_action | Default alarm action | string | `action/actions/AWS_EC2.InstanceId.Reboot/1.0` | no |
17+
| delete_on_termination | Whether the volume should be destroyed on instance termination | bool | `true` | no |
18+
| delimiter | Delimiter between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
19+
| disable_api_termination | Enable EC2 Instance Termination Protection | bool | `false` | no |
20+
| ebs_device_names | Name of the EBS device to mount | list(string) | `<list>` | no |
21+
| ebs_iops | Amount of provisioned IOPS. This must be set with a volume_type of io1 | number | `0` | no |
22+
| ebs_optimized | Launched EC2 instance will be EBS-optimized | bool | `false` | no |
23+
| ebs_volume_count | Count of EBS volumes that will be attached to the instance | number | `0` | no |
24+
| ebs_volume_size | Size of the EBS volume in gigabytes | number | `10` | no |
2525
| ebs_volume_type | The type of EBS volume. Can be standard, gp2 or io1 | string | `gp2` | no |
26-
| evaluation_periods | The number of periods over which data is compared to the specified threshold. | string | `5` | no |
27-
| generate_ssh_key_pair | If true, create a new key pair and save the pem for it to the current working directory | string | `false` | no |
28-
| instance_count | Count of ec2 instances to create | string | `1` | no |
29-
| instance_enabled | Flag to control the instance creation. Set to false if it is necessary to skip instance creation | string | `true` | no |
26+
| evaluation_periods | The number of periods over which data is compared to the specified threshold | number | `5` | no |
27+
| generate_ssh_key_pair | If true, create a new key pair and save the pem for it to the current working directory | bool | `false` | no |
28+
| instance_count | Count of ec2 instances to create | number | `1` | no |
29+
| instance_enabled | Flag to control the instance creation. Set to false if it is necessary to skip instance creation | bool | `true` | no |
3030
| instance_type | The type of the instance | string | `t2.micro` | no |
31-
| 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 |
32-
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | list | `<list>` | no |
31+
| 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 |
32+
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | list(string) | `<list>` | no |
3333
| 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 |
3434
| 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 |
35-
| metric_threshold | The value against which the specified statistic is compared | string | `1` | no |
36-
| monitoring | Launched EC2 instance will have detailed monitoring enabled | string | `true` | no |
37-
| name | Name (e.g. `bastion` or `db`) - required for `terraform-terraform-label` module | string | - | yes |
38-
| namespace | Namespace (e.g. `cp` or `cloudposse`) - required for `terraform-terraform-label` module | string | - | yes |
39-
| private_ips | Private IP address to associate with the instances in the VPC | list | `<list>` | no |
40-
| region | AWS Region the instance is launched in | string | `` | no |
41-
| root_iops | Amount of provisioned IOPS. This must be set if root_volume_type is set to `io1` | string | `0` | no |
42-
| root_volume_size | Size of the root volume in gigabytes | string | `10` | no |
35+
| metric_threshold | The value against which the specified statistic is compared | number | `1` | no |
36+
| monitoring | Launched EC2 instance will have detailed monitoring enabled | bool | `true` | no |
37+
| name | Name of the application | string | - | yes |
38+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
39+
| private_ips | Private IP address to associate with the instances in the VPC | list(string) | `<list>` | no |
40+
| region | AWS Region the instance is launched in | string | - | yes |
41+
| root_iops | Amount of provisioned IOPS. This must be set if root_volume_type is set to `io1` | number | `0` | no |
42+
| root_volume_size | Size of the root volume in gigabytes | number | `10` | no |
4343
| root_volume_type | Type of root volume. Can be standard, gp2 or io1 | string | `gp2` | no |
44-
| security_groups | List of Security Group IDs allowed to connect to the instance | list | `<list>` | no |
45-
| 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 |
44+
| security_groups | List of Security Group IDs allowed to connect to the instance | list(string) | `<list>` | no |
45+
| 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 |
4646
| ssh_key_pair | SSH key pair to be provisioned on the instance | string | `` | no |
47-
| ssh_key_pair_path | Path to where the generated key pairs will be created. Defaults to $${path.cwd} | string | `` | no |
48-
| stage | Stage (e.g. `prod`, `dev`, `staging` - required for `terraform-terraform-label` module | string | - | yes |
47+
| ssh_key_pair_path | Path to where the generated key pairs will be created. Defaults to $$${path.cwd} | string | `` | no |
48+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
4949
| statistic_level | The statistic to apply to the alarm's associated metric. Allowed values are: SampleCount, Average, Sum, Minimum, Maximum | string | `Maximum` | no |
5050
| subnet | VPC Subnet ID the instance is launched in | string | - | yes |
51-
| tags | Additional tags | map | `<map>` | no |
51+
| tags | Additional tags (_e.g._ { BusinessUnit : ABC }) | map(string) | `<map>` | no |
5252
| user_data | Instance user data. Do not pass gzip-compressed data via this argument | string | `` | no |
5353
| vpc_id | The ID of the VPC that the instance security group belongs to | string | - | yes |
54-
| welcome_message | - | string | `` | no |
54+
| welcome_message | Welcome message | string | `` | no |
5555

5656
## Outputs
5757

@@ -63,7 +63,7 @@
6363
| eip_per_instance_count | Number of EIPs per instance. |
6464
| eni_to_eip_map | Map of ENI with EIP |
6565
| ids | Disambiguated IDs list |
66-
| instance_count | Total number of instances created. |
66+
| instance_count | Total number of instances created |
6767
| network_interface_ids | IDs of the network interface that was created with the instance |
6868
| new_ssh_keypair_generated | Was a new ssh_key_pair generated |
6969
| primary_network_interface_ids | IDs of the instance's primary network interface |

0 commit comments

Comments
 (0)