Skip to content

Commit a44aacd

Browse files
daroga0002Olesia Ivanenko
authored and
Olesia Ivanenko
committed
fix: Rebuild examples (terraform-aws-modules#1625)
1 parent ad306d1 commit a44aacd

Some content is hidden

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

45 files changed

+1272
-699
lines changed

README.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Terraform module which creates Kubernetes cluster resources on AWS EKS.
1515
- Support AWS EKS Optimized or Custom AMI
1616
- Create or manage security groups that allow communication and coordination
1717

18-
1918
## Important note
2019

2120
Kubernetes is evolving a lot, and each minor version includes new features, fixes, or changes.
@@ -24,7 +23,6 @@ Kubernetes is evolving a lot, and each minor version includes new features, fixe
2423

2524
You also need to ensure that your applications and add ons are updated, or workloads could fail after the upgrade is complete. For action, you may need to take before upgrading, see the steps in the [EKS documentation](https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html).
2625

27-
2826
## Usage example
2927

3028
```hcl
@@ -61,7 +59,6 @@ module "eks" {
6159

6260
There is also a [complete example](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/complete) which shows large set of features available in the module.
6361

64-
6562
## Submodules
6663

6764
Root module calls these modules which can also be used separately to create independent resources:
@@ -71,14 +68,12 @@ Root module calls these modules which can also be used separately to create inde
7168
- [node_groups](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/modules/node_groups) - creates Managed Node Group resources
7269
-->
7370

74-
7571
## Notes
7672

7773
- By default, this module manages the `aws-auth` configmap for you (`manage_aws_auth=true`). To avoid the following [issue](https://github.com/aws/containers-roadmap/issues/654) where the EKS creation is `ACTIVE` but not ready. We implemented a "retry" logic with a [fork of the http provider](https://github.com/terraform-aws-modules/terraform-provider-http). This fork adds the support of a self-signed CA certificate. The original PR can be found [here](https://github.com/hashicorp/terraform-provider-http/pull/29).
7874

7975
- Setting `instance_refresh_enabled = true` will recreate your worker nodes without draining them first. It is recommended to install [aws-node-termination-handler](https://github.com/aws/aws-node-termination-handler) for proper node draining. Find the complete example here [instance_refresh](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/instance_refresh).
8076

81-
8277
## Documentation
8378

8479
### Official docs
@@ -93,7 +88,6 @@ Root module calls these modules which can also be used separately to create inde
9388
- [IAM Permissions](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/iam-permissions.md): Minimum IAM permissions needed to setup EKS Cluster.
9489
- [FAQ](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/faq.md): Frequently Asked Questions
9590

96-
9791
## Examples
9892

9993
There are detailed examples available for you to see how certain features of this module can be used in a straightforward way. Make sure to check them and run them before opening an issue. [Here](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/iam-permissions.md) you can find the list of the minimum IAM Permissions required to create EKS cluster.
@@ -102,14 +96,12 @@ There are detailed examples available for you to see how certain features of thi
10296
- [Bottlerocket](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/bottlerocket) - Create EKS cluster using [Bottlerocket AMI](https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami-bottlerocket.html).
10397
- [Fargate](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/fargate) - Create EKS cluster with [Fargate profiles](https://docs.aws.amazon.com/eks/latest/userguide/fargate.html) and attach Fargate profiles to an existing EKS cluster.
10498

105-
10699
## Contributing
107100

108101
Report issues/questions/feature requests on in the [issues](https://github.com/terraform-aws-modules/terraform-aws-eks/issues/new) section.
109102

110103
Full contributing [guidelines are covered here](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/.github/CONTRIBUTING.md).
111104

112-
113105
## Authors
114106

115107
This module has been originally created by [Brandon O'Connor](https://github.com/brandoconnor), and was maintained by [Max Williams](https://github.com/max-rocket-internet), [Thierno IB. BARRY](https://github.com/barryib) and many more [contributors listed here](https://github.com/terraform-aws-modules/terraform-aws-eks/graphs/contributors)!
@@ -243,9 +235,9 @@ Apache 2 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraf
243235
| <a name="input_manage_aws_auth"></a> [manage\_aws\_auth](#input\_manage\_aws\_auth) | Whether to apply the aws-auth configmap file. | `bool` | `true` | no |
244236
| <a name="input_manage_cluster_iam_resources"></a> [manage\_cluster\_iam\_resources](#input\_manage\_cluster\_iam\_resources) | Whether to let the module manage cluster IAM resources. If set to false, cluster\_iam\_role\_name must be specified. | `bool` | `true` | no |
245237
| <a name="input_manage_worker_iam_resources"></a> [manage\_worker\_iam\_resources](#input\_manage\_worker\_iam\_resources) | Whether to let the module manage worker IAM resources. If set to false, iam\_instance\_profile\_name must be specified for workers. | `bool` | `true` | no |
246-
| <a name="input_map_accounts"></a> [map\_accounts](#input\_map\_accounts) | Additional AWS account numbers to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | `list(string)` | `[]` | no |
247-
| <a name="input_map_roles"></a> [map\_roles](#input\_map\_roles) | Additional IAM roles to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | <pre>list(object({<br> rolearn = string<br> username = string<br> groups = list(string)<br> }))</pre> | `[]` | no |
248-
| <a name="input_map_users"></a> [map\_users](#input\_map\_users) | Additional IAM users to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | <pre>list(object({<br> userarn = string<br> username = string<br> groups = list(string)<br> }))</pre> | `[]` | no |
238+
| <a name="input_map_accounts"></a> [map\_accounts](#input\_map\_accounts) | Additional AWS account numbers to add to the aws-auth configmap. | `list(string)` | `[]` | no |
239+
| <a name="input_map_roles"></a> [map\_roles](#input\_map\_roles) | Additional IAM roles to add to the aws-auth configmap. | <pre>list(object({<br> rolearn = string<br> username = string<br> groups = list(string)<br> }))</pre> | `[]` | no |
240+
| <a name="input_map_users"></a> [map\_users](#input\_map\_users) | Additional IAM users to add to the aws-auth configmap. | <pre>list(object({<br> userarn = string<br> username = string<br> groups = list(string)<br> }))</pre> | `[]` | no |
249241
| <a name="input_node_groups"></a> [node\_groups](#input\_node\_groups) | Map of map of node groups to create. See `node_groups` module's documentation for more details | `any` | `{}` | no |
250242
| <a name="input_node_groups_defaults"></a> [node\_groups\_defaults](#input\_node\_groups\_defaults) | Map of values to be applied to all node groups. See `node_groups` module's documentation for more details | `any` | `{}` | no |
251243
| <a name="input_openid_connect_audiences"></a> [openid\_connect\_audiences](#input\_openid\_connect\_audiences) | List of OpenID Connect audience client IDs to add to the IRSA provider. | `list(string)` | `[]` | no |

examples/_bootstrap/main.tf

-50
This file was deleted.

examples/_bootstrap/outputs.tf

-14
This file was deleted.

examples/_bootstrap/variables.tf

Whitespace-only changes.

examples/_bootstrap/versions.tf

-9
This file was deleted.

examples/bottlerocket/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AWS EKS cluster running Bottlerocket AMI
22

3-
Configuration in this directory creates EKS cluster with nodes running [AWS Bottlerocket OS](https://github.com/bottlerocket-os/bottlerocket)
3+
Configuration in this directory creates EKS cluster with workers group running [AWS Bottlerocket OS](https://github.com/bottlerocket-os/bottlerocket)
44

55
This is a minimalistic example which shows what knobs to turn to make Bottlerocket work.
66

@@ -25,6 +25,8 @@ Note that this example may create resources which cost money. Run `terraform des
2525
|------|---------|
2626
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
2727
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
28+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | ~> 2.0 |
29+
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.4 |
2830
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
2931
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 2.0 |
3032

@@ -41,6 +43,7 @@ Note that this example may create resources which cost money. Run `terraform des
4143
| Name | Source | Version |
4244
|------|--------|---------|
4345
| <a name="module_eks"></a> [eks](#module\_eks) | ../.. | |
46+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
4447

4548
## Resources
4649

@@ -51,8 +54,10 @@ Note that this example may create resources which cost money. Run `terraform des
5154
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
5255
| [tls_private_key.nodes](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
5356
| [aws_ami.bottlerocket_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
54-
| [aws_subnet_ids.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
55-
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
57+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
58+
| [aws_eks_cluster.cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
59+
| [aws_eks_cluster_auth.cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source |
60+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5661

5762
## Inputs
5863

@@ -67,5 +72,4 @@ No inputs.
6772
| <a name="output_config_map_aws_auth"></a> [config\_map\_aws\_auth](#output\_config\_map\_aws\_auth) | A kubernetes configuration to authenticate to this EKS cluster. |
6873
| <a name="output_kubectl_config"></a> [kubectl\_config](#output\_kubectl\_config) | kubectl config as generated by the module. |
6974
| <a name="output_node_groups"></a> [node\_groups](#output\_node\_groups) | Outputs from node groups |
70-
| <a name="output_region"></a> [region](#output\_region) | AWS region. |
7175
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/bottlerocket/main.tf

+83-19
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@ provider "aws" {
33
}
44

55
locals {
6-
region = "eu-west-1"
7-
k8s_version = "1.21"
6+
name = "bottlerocket-${random_string.suffix.result}"
7+
cluster_version = "1.20"
8+
region = "eu-west-1"
89
}
910

11+
################################################################################
12+
# EKS Module
13+
################################################################################
14+
1015
module "eks" {
1116
source = "../.."
1217

13-
cluster_name = "bottlerocket-${random_string.suffix.result}"
14-
cluster_version = local.k8s_version
18+
cluster_name = local.name
19+
cluster_version = local.cluster_version
1520

16-
vpc_id = data.aws_vpc.default.id
17-
subnets = data.aws_subnet_ids.default.ids
21+
vpc_id = module.vpc.vpc_id
22+
subnets = [module.vpc.private_subnets[0], module.vpc.public_subnets[1]]
23+
fargate_subnets = [module.vpc.private_subnets[2]]
24+
25+
cluster_endpoint_private_access = true
26+
cluster_endpoint_public_access = true
1827

1928
write_kubeconfig = false
20-
manage_aws_auth = false
29+
manage_aws_auth = true
2130

2231
worker_groups_launch_template = [
2332
{
@@ -40,7 +49,7 @@ module "eks" {
4049
userdata_template_extra_args = {
4150
enable_admin_container = false
4251
enable_control_container = true
43-
aws_region = local.region
52+
aws_region = data.aws_region.current.name
4453
}
4554
# example of k8s/kubelet configuration via additional_userdata
4655
additional_userdata = <<EOT
@@ -49,6 +58,12 @@ ingress = "allowed"
4958
EOT
5059
}
5160
]
61+
62+
tags = {
63+
Example = local.name
64+
GithubRepo = "terraform-aws-eks"
65+
GithubOrg = "terraform-aws-modules"
66+
}
5267
}
5368

5469
# SSM policy for bottlerocket control container access
@@ -59,32 +74,39 @@ resource "aws_iam_role_policy_attachment" "ssm" {
5974
}
6075

6176
################################################################################
62-
# Supporting Resources
77+
# Kubernetes provider configuration
6378
################################################################################
6479

65-
data "aws_vpc" "default" {
66-
default = true
80+
data "aws_eks_cluster" "cluster" {
81+
name = module.eks.cluster_id
6782
}
6883

69-
data "aws_subnet_ids" "default" {
70-
vpc_id = data.aws_vpc.default.id
84+
data "aws_eks_cluster_auth" "cluster" {
85+
name = module.eks.cluster_id
7186
}
7287

88+
provider "kubernetes" {
89+
host = data.aws_eks_cluster.cluster.endpoint
90+
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
91+
token = data.aws_eks_cluster_auth.cluster.token
92+
}
93+
94+
################################################################################
95+
# Supporting Resources
96+
################################################################################
97+
98+
data "aws_region" "current" {}
99+
73100
data "aws_ami" "bottlerocket_ami" {
74101
most_recent = true
75102
owners = ["amazon"]
76103

77104
filter {
78105
name = "name"
79-
values = ["bottlerocket-aws-k8s-${local.k8s_version}-x86_64-*"]
106+
values = ["bottlerocket-aws-k8s-${local.cluster_version}-x86_64-*"]
80107
}
81108
}
82109

83-
resource "random_string" "suffix" {
84-
length = 8
85-
special = false
86-
}
87-
88110
resource "tls_private_key" "nodes" {
89111
algorithm = "RSA"
90112
}
@@ -93,3 +115,45 @@ resource "aws_key_pair" "nodes" {
93115
key_name = "bottlerocket-nodes-${random_string.suffix.result}"
94116
public_key = tls_private_key.nodes.public_key_openssh
95117
}
118+
119+
################################################################################
120+
# Supporting Resources
121+
################################################################################
122+
123+
data "aws_availability_zones" "available" {
124+
}
125+
126+
resource "random_string" "suffix" {
127+
length = 8
128+
special = false
129+
}
130+
131+
module "vpc" {
132+
source = "terraform-aws-modules/vpc/aws"
133+
version = "~> 3.0"
134+
135+
name = local.name
136+
cidr = "10.0.0.0/16"
137+
azs = data.aws_availability_zones.available.names
138+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
139+
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
140+
enable_nat_gateway = true
141+
single_nat_gateway = true
142+
enable_dns_hostnames = true
143+
144+
public_subnet_tags = {
145+
"kubernetes.io/cluster/${local.name}" = "shared"
146+
"kubernetes.io/role/elb" = "1"
147+
}
148+
149+
private_subnet_tags = {
150+
"kubernetes.io/cluster/${local.name}" = "shared"
151+
"kubernetes.io/role/internal-elb" = "1"
152+
}
153+
154+
tags = {
155+
Example = local.name
156+
GithubRepo = "terraform-aws-eks"
157+
GithubOrg = "terraform-aws-modules"
158+
}
159+
}

examples/bottlerocket/outputs.tf

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
output "region" {
2-
description = "AWS region."
3-
value = local.region
4-
}
5-
61
output "cluster_endpoint" {
72
description = "Endpoint for EKS control plane."
83
value = module.eks.cluster_endpoint

examples/bottlerocket/versions.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ terraform {
22
required_version = ">= 0.13.1"
33

44
required_providers {
5-
aws = ">= 3.22.0"
6-
random = ">= 2.1"
7-
tls = ">= 2.0"
5+
aws = ">= 3.22.0"
6+
local = ">= 1.4"
7+
random = ">= 2.1"
8+
kubernetes = "~> 2.0"
9+
tls = ">= 2.0"
810
}
911
}

0 commit comments

Comments
 (0)