Skip to content

Commit 7f393e7

Browse files
authored
Use string comparison for booleans (#24)
1 parent 6a4eb64 commit 7f393e7

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Module directory
22
.terraform/
33
.idea
4+
*.iml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ resource "aws_ami_from_instance" "example" {
6767

6868
| Name | Default | Description | Required |
6969
|:--------------------------------|:----------------------------------------------:|:-------------------------------------------------------------------------------------------------------|:--------:|
70+
| `region` | `` | AWS Region the instance is launched in. Optional. If not provided, the current region will be used | No |
7071
| `namespace` | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes |
7172
| `stage` | `` | Stage (e.g. `prod`, `dev`, `staging` | Yes |
7273
| `name` | `` | Name (e.g. `bastion` or `db`) | Yes |

eni.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
locals {
2-
additional_ips_count = "${var.associate_public_ip_address && var.instance_enabled && var.additional_ips_count > 0 ? var.additional_ips_count : 0}"
2+
additional_ips_count = "${var.associate_public_ip_address == "true" && var.instance_enabled == "true" && var.additional_ips_count > 0 ? var.additional_ips_count : 0}"
33
}
44

55
resource "aws_network_interface" "additional" {
66
count = "${local.additional_ips_count}"
77
subnet_id = "${var.subnet}"
88

99
security_groups = [
10-
"${compact(concat(list(var.create_default_security_group ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}",
10+
"${compact(concat(list(var.create_default_security_group == "true" ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}",
1111
]
1212

1313
tags = "${module.label.tags}"

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
instance_count = "${var.instance_enabled ? 1 : 0}"
3-
security_group_count = "${var.create_default_security_group ? 1 : 0}"
2+
instance_count = "${var.instance_enabled == "true" ? 1 : 0}"
3+
security_group_count = "${var.create_default_security_group == "true" ? 1 : 0}"
44
region = "${var.region != "" ? var.region : data.aws_region.default.name}"
55
root_iops = "${var.root_volume_type == "io1" ? var.root_iops : "0"}"
66
ebs_iops = "${var.ebs_volume_type == "io1" ? var.ebs_iops : "0"}"
@@ -68,7 +68,7 @@ module "label" {
6868
attributes = "${var.attributes}"
6969
delimiter = "${var.delimiter}"
7070
tags = "${merge(map("AZ", "${local.availability_zone}"), var.tags)}"
71-
enabled = "${local.instance_count ? "true" : "false"}"
71+
enabled = "${local.instance_count > 0 ? "true" : "false"}"
7272
}
7373

7474
resource "aws_iam_instance_profile" "default" {
@@ -103,7 +103,7 @@ resource "aws_instance" "default" {
103103
ipv6_addresses = "${var.ipv6_addresses}"
104104

105105
vpc_security_group_ids = [
106-
"${compact(concat(list(var.create_default_security_group ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}",
106+
"${compact(concat(list(var.create_default_security_group == "true" ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}",
107107
]
108108

109109
root_block_device {
@@ -117,13 +117,13 @@ resource "aws_instance" "default" {
117117
}
118118

119119
resource "aws_eip" "default" {
120-
count = "${var.associate_public_ip_address && var.instance_enabled ? 1 : 0}"
120+
count = "${var.associate_public_ip_address == "true" && var.instance_enabled == "true" ? 1 : 0}"
121121
network_interface = "${aws_instance.default.primary_network_interface_id}"
122122
vpc = "true"
123123
}
124124

125125
resource "null_resource" "eip" {
126-
count = "${var.associate_public_ip_address && var.instance_enabled ? 1 : 0}"
126+
count = "${var.associate_public_ip_address == "true" && var.instance_enabled == "true" ? 1 : 0}"
127127

128128
triggers {
129129
public_dns = "ec2-${replace(aws_eip.default.public_ip, ".", "-")}.${local.region == "us-east-1" ? "compute-1" : "${local.region}.compute"}.amazonaws.com"

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ output "ssh_key_pair" {
3030

3131
output "security_group_ids" {
3232
description = "ID on the new AWS Security Group associated with creating instance"
33-
value = "${compact(concat(list(var.create_default_security_group ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}"
33+
value = "${compact(concat(list(var.create_default_security_group == "true" ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}"
3434
}
3535

3636
output "role" {

variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ variable "security_groups" {
2828
}
2929

3030
variable "allowed_ports" {
31+
type = "list"
3132
description = "List of allowed ingress ports"
3233
default = []
3334
}
@@ -65,7 +66,7 @@ variable "tags" {
6566
}
6667

6768
variable "region" {
68-
description = "Region of instance launched in"
69+
description = "AWS Region the instance is launched in"
6970
default = ""
7071
}
7172

@@ -110,6 +111,7 @@ variable "ipv6_address_count" {
110111
}
111112

112113
variable "ipv6_addresses" {
114+
type = "list"
113115
description = "List of IPv6 addresses from the range of the subnet to associate with the primary network interface"
114116
default = []
115117
}
@@ -130,6 +132,7 @@ variable "root_iops" {
130132
}
131133

132134
variable "ebs_device_name" {
135+
type = "list"
133136
description = "Name of the ebs device to mount"
134137
default = ["/dev/xvdb", "/dev/xvdc", "/dev/xvdd", "/dev/xvde", "/dev/xvdf", "/dev/xvdg", "/dev/xvdh", "/dev/xvdi", "/dev/xvdj", "/dev/xvdk", "/dev/xvdl", "/dev/xvdm", "/dev/xvdn", "/dev/xvdo", "/dev/xvdp", "/dev/xvdq", "/dev/xvdr", "/dev/xvds", "/dev/xvdt", "/dev/xvdu", "/dev/xvdv", "/dev/xvdw", "/dev/xvdx", "/dev/xvdy", "/dev/xvdz"]
135138
}

0 commit comments

Comments
 (0)