Skip to content

Commit 71182e0

Browse files
committed
Be DRY; use terraform-aws-util//modules/get-subnets
1 parent 2d781d6 commit 71182e0

File tree

6 files changed

+21
-33
lines changed

6 files changed

+21
-33
lines changed

.github/workflows/terraform.yml

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020

2121
- name: terraform setup
2222
uses: hashicorp/setup-terraform@v1
23-
with:
24-
terraform_version: 0.12.29
2523
# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
2624

2725
# TODO: This step duplicates work done by the Makefile.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hashicorp/terraform:0.12
1+
FROM hashicorp/terraform
22

33
RUN apk add make
44

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module "service_name" {
7474
7575
network_configuration = {
7676
assign_public_ip = true
77-
tier = "public"
77+
subnet_type = "public"
7878
vpc = "my-vpc"
7979
}
8080
}
@@ -92,8 +92,8 @@ module "service_name" {
9292
}
9393
9494
network_configuration = {
95-
tier = "nat"
96-
vpc = "my-vpc"
95+
subnet_id = "campus"
96+
vpc = "my-vpc"
9797
}
9898
}
9999
```
@@ -473,12 +473,12 @@ EC2 Container Service Developer Guide.](https://docs.aws.amazon.com/AmazonECS/la
473473

474474
A `network_configuration` block supports the following:
475475

476-
* `tier` - (Optional) A subnet tier tag (e.g., public, private, nat) to determine subnets to be associated with the task orservice.
476+
* `subnet_type` - (Required) Subnet type (e.g., 'campus', 'private', 'public') for resource placement.
477477

478478
* `vpc` - (Optional) The name of the virtual private cloud to be associated with the task or
479-
service. **NOTE:** Required when using `tier`.
479+
service. **NOTE:** Required when using `subnet_type`.
480480

481-
* `subnets` - (Required) The subnet IDs to associated with the task or service. **NOTE:** Optional when using `tier`.
481+
* `subnets` - (Required) The subnet IDs to associated with the task or service. **NOTE:** Optional when using `subnet_type`.
482482

483483
* `security_groups` - (Optional) The security groups associated with
484484
the task or service. If you do not specify a security group, the
@@ -503,9 +503,9 @@ For more information, see [Task Networking](https://docs.aws.amazon.com/AmazonEC
503503
> Note: `network_configuration` is only supported when `network_mode`
504504
> is `aws_vpc`.
505505
>
506-
> Note: The `tier` and `subnet` attributes can be used together. In this case the subnets
506+
> Note: The `subnet_type` and `subnet` attributes can be used together. In this case the subnets
507507
> to be associated with the service consist of the union of the subnets defined explicitly
508-
> in `subnet` and derived from `tier` and `vpc`.
508+
> in `subnet` and derived from `subnet_type` and `vpc`.
509509
510510
`service_discovery`
511511
-----------------

data.tf

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22
all_subnets = distinct(
3-
concat(flatten(data.aws_subnet_ids.selected.*.ids), local.subnets),
3+
concat(flatten(module.get-subnets.subnets.ids), local.subnets),
44
)
55
lb_vpc_id = element(concat(data.aws_lb.selected.*.vpc_id, [""]), 0)
66
subnet_vpc_id = element(concat(data.aws_subnet.selected.*.vpc_id, [""]), 0)
@@ -12,6 +12,13 @@ data "aws_ecs_cluster" "selected" {
1212
cluster_name = var.cluster
1313
}
1414

15+
16+
module "get-subnets" {
17+
source = "github.com/techservicesillinois/terraform-aws-util//modules/get-subnets?ref=v3.0.4"
18+
19+
subnet_type = local.subnet_type
20+
vpc = local.vpc
21+
}
1522
## LB data sources
1623

1724
data "aws_lb" "selected" {
@@ -41,20 +48,3 @@ data "aws_subnet" "selected" {
4148
count = length(var.network_configuration) > 0 ? 1 : 0
4249
id = local.all_subnets[0]
4350
}
44-
45-
data "aws_vpc" "selected" {
46-
count = local.tier != "" ? 1 : 0
47-
48-
tags = {
49-
Name = local.vpc
50-
}
51-
}
52-
53-
data "aws_subnet_ids" "selected" {
54-
count = local.tier != "" ? 1 : 0
55-
vpc_id = data.aws_vpc.selected[0].id
56-
57-
tags = {
58-
Tier = local.tier
59-
}
60-
}

locals.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ locals {
6262
lookup(var.network_configuration, "security_group_names", ""),
6363
),
6464
)
65-
subnets = compact(split(" ", lookup(var.network_configuration, "subnets", "")))
66-
tier = lookup(var.network_configuration, "tier", "")
67-
vpc = lookup(var.network_configuration, "vpc", "")
65+
subnets = compact(split(" ", lookup(var.network_configuration, "subnets", "")))
66+
subnet_type = lookup(var.network_configuration, "subnet_type", "")
67+
vpc = lookup(var.network_configuration, "vpc", "")
6868
}
6969

7070
locals {

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
terraform {
2-
required_version = ">= 0.12"
2+
required_version = ">= 1.1"
33
}

0 commit comments

Comments
 (0)