Skip to content

Commit

Permalink
Add enabled variable and update docs (#21)
Browse files Browse the repository at this point in the history
* Add enabled variable and update docs

So we can boolean creation of these resources from the caller module

* Update main.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update variables.tf

Co-Authored-By: joshmyers <[email protected]>

* Update main.tf

Co-Authored-By: joshmyers <[email protected]>

* Update outputs.tf

Co-Authored-By: joshmyers <[email protected]>

* Update README docs
  • Loading branch information
joshmyers authored Jan 23, 2019
1 parent a1e6e80 commit 70c53a0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Available targets:
lint Lint terraform code
```

## Inputs

| Name | Description | Type | Default | Required |
Expand All @@ -85,10 +86,11 @@ Available targets:
| availability_zones | Availability Zone IDs | list | - | yes |
| aws_region | AWS region ID | string | - | yes |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| encrypted | If true, the disk will be encrypted. | string | `false` | no |
| mount_target_ip_address | The address (within the address range of the specified subnet) at which the file system may be mounted via the mount target. | string | `` | no |
| name | Name (_e.g._ `app` or `wordpress`) | string | `app` | no |
| namespace | Namespace (_e.g._ `cp` or `cloudposse`) | string | `global` | no |
| namespace | Namespace (_e.g._ `eg` or `cp`) | string | `global` | no |
| performance_mode | The file system performance mode. Can be either `generalPurpose` or `maxIO` | string | `generalPurpose` | no |
| provisioned_throughput_in_mibps | The throughput, measured in MiB/s, that you want to provision for the file system. Only applicable with throughput_mode set to provisioned. | string | `0` | no |
| security_groups | AWS security group IDs to allow to connect to the EFS | list | - | yes |
Expand All @@ -107,10 +109,10 @@ Available targets:
| dns_name | DNS name |
| host | Assigned DNS-record for the EFS |
| id | EFS ID |
| mount_target_dns_names | List of DNS names for the given subnet/AZ per documented convention. |
| mount_target_dns_names | List of DNS names for the given subnet/AZ per documented convention |
| mount_target_ids | List of IDs of the EFS mount targets (one per Availability Zone) |
| mount_target_ips | List of IPs of the EFS mount targets (one per Availability Zone) |
| network_interface_ids | The IDs of the network interface that Amazon EFS created when it created the mount target. |
| network_interface_ids | The IDs of the network interface that Amazon EFS created when it created the mount target |



Expand Down
8 changes: 5 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

## Inputs

| Name | Description | Type | Default | Required |
Expand All @@ -6,10 +7,11 @@
| availability_zones | Availability Zone IDs | list | - | yes |
| aws_region | AWS region ID | string | - | yes |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| encrypted | If true, the disk will be encrypted. | string | `false` | no |
| mount_target_ip_address | The address (within the address range of the specified subnet) at which the file system may be mounted via the mount target. | string | `` | no |
| name | Name (_e.g._ `app` or `wordpress`) | string | `app` | no |
| namespace | Namespace (_e.g._ `cp` or `cloudposse`) | string | `global` | no |
| namespace | Namespace (_e.g._ `eg` or `cp`) | string | `global` | no |
| performance_mode | The file system performance mode. Can be either `generalPurpose` or `maxIO` | string | `generalPurpose` | no |
| provisioned_throughput_in_mibps | The throughput, measured in MiB/s, that you want to provision for the file system. Only applicable with throughput_mode set to provisioned. | string | `0` | no |
| security_groups | AWS security group IDs to allow to connect to the EFS | list | - | yes |
Expand All @@ -28,8 +30,8 @@
| dns_name | DNS name |
| host | Assigned DNS-record for the EFS |
| id | EFS ID |
| mount_target_dns_names | List of DNS names for the given subnet/AZ per documented convention. |
| mount_target_dns_names | List of DNS names for the given subnet/AZ per documented convention |
| mount_target_ids | List of IDs of the EFS mount targets (one per Availability Zone) |
| mount_target_ips | List of IPs of the EFS mount targets (one per Availability Zone) |
| network_interface_ids | The IDs of the network interface that Amazon EFS created when it created the mount target. |
| network_interface_ids | The IDs of the network interface that Amazon EFS created when it created the mount target |

20 changes: 14 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Define composite variables for resources
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.5"
enabled = "${var.enabled}"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
Expand All @@ -9,7 +10,13 @@ module "label" {
tags = "${var.tags}"
}

locals {
enabled = "${var.enabled == "true"}"
dns_name = "${join("", aws_efs_file_system.default.*.id)}.efs.${var.aws_region}.amazonaws.com"
}

resource "aws_efs_file_system" "default" {
count = "${local.enabled ? 1 : 0}"
tags = "${module.label.tags}"
encrypted = "${var.encrypted}"
performance_mode = "${var.performance_mode}"
Expand All @@ -18,14 +25,15 @@ resource "aws_efs_file_system" "default" {
}

resource "aws_efs_mount_target" "default" {
count = "${length(var.availability_zones)}"
file_system_id = "${aws_efs_file_system.default.id}"
count = "${local.enabled && length(var.availability_zones) > 0 ? length(var.availability_zones) : 0}"
file_system_id = "${join("", aws_efs_file_system.default.*.id)}"
ip_address = "${var.mount_target_ip_address}"
subnet_id = "${element(var.subnets, count.index)}"
security_groups = ["${aws_security_group.default.id}"]
security_groups = ["${join("", aws_security_group.default.*.id)}"]
}

resource "aws_security_group" "default" {
count = "${local.enabled ? 1 : 0}"
name = "${module.label.id}"
description = "EFS"
vpc_id = "${var.vpc_id}"
Expand Down Expand Up @@ -53,11 +61,11 @@ resource "aws_security_group" "default" {

module "dns" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.5"
enabled = "${length(var.zone_id) > 0 ? "true" : "false"}"
enabled = "${local.enabled && length(var.zone_id) > 0 ? "true" : "false"}"
name = "${module.label.id}"
namespace = "${var.namespace}"
stage = "${var.stage}"
ttl = 60
zone_id = "${var.zone_id}"
records = ["${aws_efs_file_system.default.id}.efs.${var.aws_region}.amazonaws.com"]
records = ["${local.dns_name}"]
}
20 changes: 10 additions & 10 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
output "arn" {
value = "${aws_efs_file_system.default.arn}"
value = "${local.enabled ? join("", aws_efs_file_system.default.*.arn) : "" }"
description = "EFS ARN"
}

output "id" {
value = "${aws_efs_file_system.default.id}"
value = "${local.enabled ? join("", aws_efs_file_system.default.*.id) : "" }"
description = "EFS ID"
}

output "host" {
value = "${module.dns.hostname}"
value = "${local.enabled ? module.dns.hostname : "" }"
description = "Assigned DNS-record for the EFS"
}

output "dns_name" {
value = "${aws_efs_file_system.default.dns_name}"
value = "${local.enabled ? local.dns_name : "" }"
description = "DNS name"
}

output "mount_target_dns_names" {
value = ["${aws_efs_mount_target.default.*.dns_name}"]
description = "List of DNS names for the given subnet/AZ per documented convention."
value = ["${local.enabled ? aws_efs_mount_target.default.*.dns_name : list("") }"]
description = "List of DNS names for the given subnet/AZ per documented convention"
}

output "mount_target_ids" {
value = ["${aws_efs_mount_target.default.*.id}"]
value = ["${local.enabled ? aws_efs_mount_target.default.*.id : list("") }"]
description = "List of IDs of the EFS mount targets (one per Availability Zone)"
}

output "mount_target_ips" {
value = ["${aws_efs_mount_target.default.*.ip_address}"]
value = ["${local.enabled ? aws_efs_mount_target.default.*.ip_address : list("") }"]
description = "List of IPs of the EFS mount targets (one per Availability Zone)"
}

output "network_interface_ids" {
value = ["${aws_efs_mount_target.default.*.network_interface_id}"]
description = "The IDs of the network interface that Amazon EFS created when it created the mount target."
value = ["${local.enabled ? aws_efs_mount_target.default.*.network_interface_id : list("") }"]
description = "The IDs of the network interface that Amazon EFS created when it created the mount target"
}
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
variable "enabled" {
type = "string"
default = "true"
description = "Set to false to prevent the module from creating any resources"
}

variable "namespace" {
default = "global"
description = "Namespace (_e.g._ `cp` or `cloudposse`)"
description = "Namespace (_e.g._ `eg` or `cp`)"
}

variable "stage" {
Expand Down

0 comments on commit 70c53a0

Please sign in to comment.