Skip to content

Commit 43495fd

Browse files
rsrchboyactions-botosterman
authored
Update against single instance module (#9)
* Use 0.16.0 of null-label module * Be kind when launching on auto-assign ipv6 subnets * Bump key-pair module to latest (0.9.0) * Add a `name` output * Allow for a permissions boundry to be set * Hark, a README! * Updated README.md Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> Co-authored-by: Erik Osterman <erik@cloudposse.com>
1 parent 058b482 commit 43495fd

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Available targets:
217217
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
218218
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
219219
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
220+
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | `string` | `""` | no |
220221
| evaluation\_periods | The number of periods over which data is compared to the specified threshold | `number` | `5` | no |
221222
| 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 |
222223
| instance\_count | Count of ec2 instances to create | `number` | `1` | no |
@@ -230,6 +231,7 @@ Available targets:
230231
| monitoring | Launched EC2 instance will have detailed monitoring enabled | `bool` | `true` | no |
231232
| name | Name of the application | `string` | n/a | yes |
232233
| namespace | Namespace (e.g. `eg` or `cp`) | `string` | `""` | no |
234+
| permissions\_boundary\_arn | Policy ARN to attach to instance role as a permissions boundary | `string` | `""` | no |
233235
| private\_ips | Private IP address to associate with the instances in the VPC | `list(string)` | `[]` | no |
234236
| region | AWS Region the instance is launched in | `string` | n/a | yes |
235237
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
@@ -258,6 +260,7 @@ Available targets:
258260
| eni\_to\_eip\_map | Map of ENI with EIP |
259261
| ids | Disambiguated IDs list |
260262
| instance\_count | Total number of instances created |
263+
| name | Instance(s) name |
261264
| network\_interface\_ids | IDs of the network interface that was created with the instance |
262265
| new\_ssh\_keypair\_generated | Was a new ssh\_key\_pair generated |
263266
| primary\_network\_interface\_ids | IDs of the instance's primary network interface |
@@ -423,8 +426,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
423426

424427
### Contributors
425428

426-
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]<br/>[Jamie Nelson][Jamie-BitFlight_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]<br/>[Vladimir][SweetOps_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
427-
|---|---|---|---|
429+
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]<br/>[Jamie Nelson][Jamie-BitFlight_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]<br/>[Vladimir][SweetOps_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Chris Weyl][rsrchboy_avatar]][rsrchboy_homepage]<br/>[Chris Weyl][rsrchboy_homepage] |
430+
|---|---|---|---|---|
428431

429432
[osterman_homepage]: https://github.com/osterman
430433
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
@@ -434,6 +437,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
434437
[SweetOps_avatar]: https://img.cloudposse.com/150x150/https://github.com/SweetOps.png
435438
[aknysh_homepage]: https://github.com/aknysh
436439
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
440+
[rsrchboy_homepage]: https://github.com/rsrchboy
441+
[rsrchboy_avatar]: https://img.cloudposse.com/150x150/https://github.com/rsrchboy.png
437442

438443
[![README Footer][readme_footer_img]][readme_footer_link]
439444
[![Beacon][beacon]][website]

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ contributors:
127127
github: "SweetOps"
128128
- name: "Andriy Knysh"
129129
github: "aknysh"
130+
- name: "Chris Weyl"
131+
github: "rsrchboy"

docs/terraform.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
3939
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
4040
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
41+
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | `string` | `""` | no |
4142
| evaluation\_periods | The number of periods over which data is compared to the specified threshold | `number` | `5` | no |
4243
| 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 |
4344
| instance\_count | Count of ec2 instances to create | `number` | `1` | no |
@@ -51,6 +52,7 @@
5152
| monitoring | Launched EC2 instance will have detailed monitoring enabled | `bool` | `true` | no |
5253
| name | Name of the application | `string` | n/a | yes |
5354
| namespace | Namespace (e.g. `eg` or `cp`) | `string` | `""` | no |
55+
| permissions\_boundary\_arn | Policy ARN to attach to instance role as a permissions boundary | `string` | `""` | no |
5456
| private\_ips | Private IP address to associate with the instances in the VPC | `list(string)` | `[]` | no |
5557
| region | AWS Region the instance is launched in | `string` | n/a | yes |
5658
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
@@ -79,6 +81,7 @@
7981
| eni\_to\_eip\_map | Map of ENI with EIP |
8082
| ids | Disambiguated IDs list |
8183
| instance\_count | Total number of instances created |
84+
| name | Instance(s) name |
8285
| network\_interface\_ids | IDs of the network interface that was created with the instance |
8386
| new\_ssh\_keypair\_generated | Was a new ssh\_key\_pair generated |
8487
| primary\_network\_interface\_ids | IDs of the instance's primary network interface |

main.tf

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ data "aws_ami" "info" {
5959
}
6060

6161
module "label" {
62-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1"
63-
namespace = var.namespace
64-
stage = var.stage
65-
name = var.name
66-
attributes = var.attributes
67-
delimiter = var.delimiter
62+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
63+
namespace = var.namespace
64+
stage = var.stage
65+
environment = var.environment
66+
name = var.name
67+
attributes = var.attributes
68+
delimiter = var.delimiter
6869
tags = merge(
6970
{
7071
AZ = local.availability_zone
@@ -81,10 +82,11 @@ resource "aws_iam_instance_profile" "default" {
8182
}
8283

8384
resource "aws_iam_role" "default" {
84-
count = signum(local.instance_count)
85-
name = module.label.id
86-
path = "/"
87-
assume_role_policy = data.aws_iam_policy_document.default.json
85+
count = signum(local.instance_count)
86+
name = module.label.id
87+
path = "/"
88+
assume_role_policy = data.aws_iam_policy_document.default.json
89+
permissions_boundary = length(var.permissions_boundary_arn) > 0 ? var.permissions_boundary_arn : null
8890
}
8991

9092
resource "aws_instance" "default" {
@@ -102,8 +104,8 @@ resource "aws_instance" "default" {
102104
monitoring = var.monitoring
103105
private_ip = concat(var.private_ips, [""])[min(length(var.private_ips), count.index)]
104106
source_dest_check = var.source_dest_check
105-
ipv6_address_count = var.ipv6_address_count
106-
ipv6_addresses = var.ipv6_addresses
107+
ipv6_address_count = var.ipv6_address_count < 0 ? null : var.ipv6_address_count
108+
ipv6_addresses = length(var.ipv6_addresses) > 0 ? var.ipv6_addresses : null
107109

108110
vpc_security_group_ids = compact(
109111
concat(
@@ -134,8 +136,9 @@ resource "aws_instance" "default" {
134136
##
135137

136138
module "ssh_key_pair" {
137-
source = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=tags/0.4.0"
139+
source = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=tags/0.9.0"
138140
namespace = var.namespace
141+
environment = var.environment
139142
stage = var.stage
140143
name = var.name
141144
ssh_public_key_path = local.ssh_key_pair_path

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ output "ids" {
2323
value = aws_instance.default.*.id
2424
}
2525

26+
output "name" {
27+
description = "Instance(s) name"
28+
value = module.label.id
29+
}
30+
2631
output "aws_key_pair_name" {
2732
description = "Name of AWS key pair"
2833
value = signum(length(var.ssh_key_pair)) == 1 ? var.ssh_key_pair : var.generate_ssh_key_pair ? module.ssh_key_pair.key_name : ""

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ variable "stage" {
1010
default = ""
1111
}
1212

13+
variable "environment" {
14+
type = string
15+
description = "Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT'"
16+
default = ""
17+
}
18+
1319
variable "name" {
1420
type = string
1521
description = "Name of the application"
@@ -291,3 +297,9 @@ variable "instance_count" {
291297
description = "Count of ec2 instances to create"
292298
default = 1
293299
}
300+
301+
variable "permissions_boundary_arn" {
302+
type = string
303+
description = "Policy ARN to attach to instance role as a permissions boundary"
304+
default = ""
305+
}

0 commit comments

Comments
 (0)