Skip to content

Commit

Permalink
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#8)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aknysh authored Jul 18, 2019
1 parent 2b74c66 commit 27190f9
Show file tree
Hide file tree
Showing 28 changed files with 1,200 additions and 512 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*.iml
**/terraform.tfstate
**/terraform.tfstate.backup
**/terraform.tfvars
**/*.pem
**/*.pub

.build-harness
build-harness
build-harness
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

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

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
131 changes: 66 additions & 65 deletions README.md

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-ec2-instance-group

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance-group.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-aws-ec2-instance-group"
- name: "Codefresh Build Status"
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ec2-instance-group?type=cf-1"
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d2c103fd17b10438bdd81e2"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance-group.svg"
url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group/releases/latest"
Expand All @@ -45,7 +45,7 @@ description: |-
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.
**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).
**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).
Included features:
Expand All @@ -66,18 +66,17 @@ usage: |-
```hcl
module "instance" {
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance-group.git?ref=master"
namespace = "cp"
namespace = "eg"
stage = "prod"
name = "app"
ami = "ami-a4dc46db"
ami_owner = "099720109477"
ssh_key_pair = "${var.ssh_key_pair}"
instance_type = "${var.instance_type}"
vpc_id = "${var.vpc_id}"
security_groups = ["${var.security_groups}"]
subnet = "${var.subnet}"
instance_count = "3"
ssh_key_pair = var.ssh_key_pair
instance_type = var.instance_type
vpc_id = var.vpc_id
security_groups = var.security_groups
subnet = var.subnet
instance_count = 3
}
```
Expand All @@ -86,21 +85,20 @@ usage: |-
```hcl
module "kafka_instance" {
source = "git::https://github.com/cloudposse/terraform-aws-ec2-instance-group.git?ref=master"
namespace = "cp"
namespace = "eg"
stage = "prod"
name = "app"
ami = "ami-a4dc46db"
ami_owner = "099720109477"
ssh_key_pair = "${var.ssh_key_pair}"
vpc_id = "${var.vpc_id}"
security_groups = ["${var.security_groups}"]
subnet = "${var.subnet}"
associate_public_ip_address = "true"
additional_ips_count = "1"
ebs_volume_count = "2"
allowed_ports = ["22", "80", "443"]
instance_count = "3"
ssh_key_pair = var.ssh_key_pair
vpc_id = var.vpc_id
security_groups = var.security_groups
subnet = var.subnet
associate_public_ip_address = true
additional_ips_count = 1
ebs_volume_count = 2
allowed_ports = [22, 80, 443]
instance_count = 3
}
```
Expand All @@ -114,11 +112,12 @@ usage: |-
It is necessary to run `terraform get` or `terraform init` to download this module.
Now reference the label when creating an instance (for example):
```hcl
resource "aws_ami_from_instance" "example" {
count = "${length(module.instance.*.id)}"
name = "terraform-example"
source_instance_id = "${element(module.instance.*.id, count.index)}"
count = length(module.instance.*.id)
name = "app"
source_instance_id = element(module.instance.*.id, count.index)
}
```
Expand All @@ -139,3 +138,5 @@ contributors:
github: "Jamie-BitFlight"
- name: "Vladimir"
github: "SweetOps"
- name: "Andriy Knysh"
github: "aknysh"
22 changes: 11 additions & 11 deletions cloud_watch_alarm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ locals {
}

resource "aws_cloudwatch_metric_alarm" "default" {
count = "${local.instance_count}"
count = local.instance_count
alarm_name = "${module.label.id}-${count.index}"
comparison_operator = "${var.comparison_operator}"
evaluation_periods = "${var.evaluation_periods}"
metric_name = "${var.metric_name}"
namespace = "${var.metric_namespace}"
period = "${var.applying_period}"
statistic = "${var.statistic_level}"
threshold = "${var.metric_threshold}"
comparison_operator = var.comparison_operator
evaluation_periods = var.evaluation_periods
metric_name = var.metric_name
namespace = var.metric_namespace
period = var.applying_period
statistic = var.statistic_level
threshold = var.metric_threshold

dimensions {
InstanceId = "${element(sort(aws_instance.default.*.id), count.index)}"
dimensions = {
InstanceId = sort(aws_instance.default.*.id)[count.index]
}

alarm_actions = [
"${local.action}",
local.action
]
}
74 changes: 74 additions & 0 deletions codefresh/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '1.0'

stages:
- Prepare
- Test

steps:
wait:
title: Wait
stage: Prepare
image: codefresh/cli:latest
commands:
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
retry:
maxAttempts: 10
delay: 20
exponentialFactor: 1.1

main_clone:
title: "Clone repository"
type: git-clone
stage: Prepare
description: "Initialize"
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
git: CF-default
revision: ${{CF_REVISION}}

clean_init:
title: Prepare build-harness and test-harness
image: ${{TEST_IMAGE}}
stage: Prepare
commands:
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- make init
- git -C build-harness checkout master
- make -C test/ clean init TEST_HARNESS_BRANCH=master
- make -C test/src clean init
- find . -type d -name '.terraform' | xargs rm -rf
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;

test:
type: "parallel"
title: "Run tests"
description: "Run all tests in parallel"
stage: Test
steps:
test_readme_lint:
title: "Test README.md updated"
stage: "Test"
image: ${{TEST_IMAGE}}
description: Test "readme/lint"
commands:
- make readme/lint

test_module:
title: Test module with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ module

test_examples_complete:
title: Test "examples/complete" with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ examples/complete

test_examples_complete_terratest:
title: Test "examples/complete" with terratest
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/src
78 changes: 39 additions & 39 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@

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

## Outputs

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

0 comments on commit 27190f9

Please sign in to comment.