Skip to content

Commit 2bdf7d7

Browse files
authored
refactor: Refactoring to match the rest of terraform-aws-modules (#1583)
1 parent 619b4a0 commit 2bdf7d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1338
-1025
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
repos:
2-
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.50.0
4-
hooks:
5-
- id: terraform_fmt
6-
- id: terraform_docs
7-
- id: terraform_validate
8-
- id: terraform_tflint
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.50.0
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_validate
7+
- id: terraform_docs
8+
- id: terraform_tflint
9+
args:
10+
- '--args=--only=terraform_deprecated_interpolation'
11+
- '--args=--only=terraform_deprecated_index'
12+
- '--args=--only=terraform_unused_declarations'
13+
- '--args=--only=terraform_comment_syntax'
14+
- '--args=--only=terraform_documented_outputs'
15+
- '--args=--only=terraform_documented_variables'
16+
- '--args=--only=terraform_typed_variables'
17+
- '--args=--only=terraform_module_pinned_source'
18+
# - '--args=--only=terraform_naming_convention'
19+
- '--args=--only=terraform_required_version'
20+
- '--args=--only=terraform_required_providers'
21+
- '--args=--only=terraform_standard_module_structure'
22+
- '--args=--only=terraform_workspace_remote'
23+
- repo: git://github.com/pre-commit/pre-commit-hooks
24+
rev: v4.0.1
25+
hooks:
26+
- id: check-merge-conflict

README.md

Lines changed: 63 additions & 81 deletions
Large diffs are not rendered by default.

aws_auth.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ locals {
1818
]
1919

2020
auth_worker_roles = [
21-
for index in range(0, var.create_eks ? local.worker_group_count : 0) : {
21+
for index in range(0, var.create_eks ? local.worker_group_launch_configuration_count : 0) : {
2222
worker_role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/${element(
2323
coalescelist(
2424
aws_iam_instance_profile.workers.*.role,
@@ -61,8 +61,7 @@ locals {
6161
}
6262

6363
resource "kubernetes_config_map" "aws_auth" {
64-
count = var.create_eks && var.manage_aws_auth ? 1 : 0
65-
depends_on = [data.http.wait_for_cluster[0]]
64+
count = var.create_eks && var.manage_aws_auth ? 1 : 0
6665

6766
metadata {
6867
name = "aws-auth"
@@ -88,4 +87,6 @@ resource "kubernetes_config_map" "aws_auth" {
8887
mapUsers = yamlencode(var.map_users)
8988
mapAccounts = yamlencode(var.map_accounts)
9089
}
90+
91+
depends_on = [data.http.wait_for_cluster[0]]
9192
}

data.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ data "aws_iam_policy_document" "workers_assume_role_policy" {
1818
}
1919

2020
data "aws_ami" "eks_worker" {
21-
count = local.worker_has_linux_ami ? 1 : 0
21+
count = contains(local.worker_groups_platforms, "linux") ? 1 : 0
2222

2323
filter {
2424
name = "name"
@@ -31,7 +31,7 @@ data "aws_ami" "eks_worker" {
3131
}
3232

3333
data "aws_ami" "eks_worker_windows" {
34-
count = local.worker_has_windows_ami ? 1 : 0
34+
count = contains(local.worker_groups_platforms, "windows") ? 1 : 0
3535

3636
filter {
3737
name = "name"
@@ -65,11 +65,13 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" {
6565

6666
data "aws_iam_role" "custom_cluster_iam_role" {
6767
count = var.manage_cluster_iam_resources ? 0 : 1
68-
name = var.cluster_iam_role_name
68+
69+
name = var.cluster_iam_role_name
6970
}
7071

7172
data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile" {
72-
count = var.manage_worker_iam_resources ? 0 : local.worker_group_count
73+
count = var.manage_worker_iam_resources ? 0 : local.worker_group_launch_configuration_count
74+
7375
name = lookup(
7476
var.worker_groups[count.index],
7577
"iam_instance_profile_name",
@@ -79,6 +81,7 @@ data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile" {
7981

8082
data "aws_iam_instance_profile" "custom_worker_group_launch_template_iam_instance_profile" {
8183
count = var.manage_worker_iam_resources ? 0 : local.worker_group_launch_template_count
84+
8285
name = lookup(
8386
var.worker_groups_launch_template[count.index],
8487
"iam_instance_profile_name",
@@ -87,9 +90,10 @@ data "aws_iam_instance_profile" "custom_worker_group_launch_template_iam_instanc
8790
}
8891

8992
data "http" "wait_for_cluster" {
90-
count = var.create_eks && var.manage_aws_auth ? 1 : 0
93+
count = var.create_eks && var.manage_aws_auth ? 1 : 0
94+
9195
url = format("%s/healthz", aws_eks_cluster.this[0].endpoint)
92-
ca_certificate = base64decode(coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0])
96+
ca_certificate = base64decode(local.cluster_auth_base64)
9397
timeout = var.wait_for_cluster_timeout
9498

9599
depends_on = [

examples/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/_bootstrap/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Various bootstrap resources required for other EKS examples
2+
3+
Configuration in this directory creates some resources required in other EKS examples (such as VPC).
4+
5+
The resources created here are free (no NAT gateways here) and they can reside in test AWS account.
6+
7+
## Usage
8+
9+
To run this example you need to execute:
10+
11+
```bash
12+
$ terraform init
13+
$ terraform plan
14+
$ terraform apply
15+
```
16+
17+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
18+
19+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20+
## Requirements
21+
22+
| Name | Version |
23+
|------|---------|
24+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
26+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 1.11 |
27+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
28+
29+
## Providers
30+
31+
| Name | Version |
32+
|------|---------|
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.22.0 |
34+
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |
35+
36+
## Modules
37+
38+
| Name | Source | Version |
39+
|------|--------|---------|
40+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
41+
42+
## Resources
43+
44+
| Name | Type |
45+
|------|------|
46+
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
47+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
48+
49+
## Inputs
50+
51+
No inputs.
52+
53+
## Outputs
54+
55+
| Name | Description |
56+
|------|-------------|
57+
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of EKS Cluster used in tags for subnets |
58+
| <a name="output_region"></a> [region](#output\_region) | AWS region |
59+
| <a name="output_vpc"></a> [vpc](#output\_vpc) | Complete output of VPC module |
60+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/_bootstrap/main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
locals {
6+
region = "eu-west-1"
7+
name = "bootstrap-example"
8+
vpc_cidr = "10.0.0.0/16"
9+
10+
cluster_name = "test-eks-${random_string.suffix.result}"
11+
}
12+
13+
data "aws_availability_zones" "available" {}
14+
15+
resource "random_string" "suffix" {
16+
length = 8
17+
special = false
18+
}
19+
20+
################################################################################
21+
# Supporting Resources
22+
################################################################################
23+
24+
module "vpc" {
25+
source = "terraform-aws-modules/vpc/aws"
26+
version = "~> 3.0"
27+
28+
name = local.name
29+
cidr = "10.0.0.0/16"
30+
31+
azs = data.aws_availability_zones.available.names
32+
public_subnets = [for k, v in data.aws_availability_zones.available.names : cidrsubnet(local.vpc_cidr, 8, k)]
33+
private_subnets = [for k, v in data.aws_availability_zones.available.names : cidrsubnet(local.vpc_cidr, 8, k + 10)]
34+
35+
# NAT Gateway is disabled in the examples primarily to save costs and be able to recreate VPC faster.
36+
enable_nat_gateway = false
37+
single_nat_gateway = false
38+
39+
enable_dns_hostnames = true
40+
41+
public_subnet_tags = {
42+
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
43+
"kubernetes.io/role/elb" = "1"
44+
}
45+
46+
private_subnet_tags = {
47+
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
48+
"kubernetes.io/role/internal-elb" = "1"
49+
}
50+
}

examples/_bootstrap/outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "region" {
2+
description = "AWS region"
3+
value = local.region
4+
}
5+
6+
output "cluster_name" {
7+
description = "Name of EKS Cluster used in tags for subnets"
8+
value = local.cluster_name
9+
}
10+
11+
output "vpc" {
12+
description = "Complete output of VPC module"
13+
value = module.vpc
14+
}

examples/_bootstrap/variables.tf

Whitespace-only changes.

examples/spot_instances/versions.tf renamed to examples/_bootstrap/versions.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ terraform {
33

44
required_providers {
55
aws = ">= 3.22.0"
6-
local = ">= 1.4"
76
random = ">= 2.1"
8-
kubernetes = "~> 1.11"
7+
kubernetes = ">= 1.11"
98
}
109
}

0 commit comments

Comments
 (0)