Skip to content

Commit

Permalink
feat!: support generic adoption variables (#140)
Browse files Browse the repository at this point in the history
### Motivation

For adopt old existing clusters into new IaC.

### Modifications

Upgrade provider version:

- terraform required_version to >= 1.3.2
- aws provider to >= 5.75
- kubernetes provider to >= 2.32

Upgrade module version:

- eks module to 20.29.0

Added new variables:

- `cluster_encryption_config`
- `bootstrap_self_managed_addons`
- `cluster_iam`
- `cluster_networking`
- `node_groups`

Updated outputs:

- `eks_cluster_id` renamed to `eks_cluster_name`

### Verifying this change

It has been verified in test environment.

### Documentation

- [x] `doc`

---------

Co-authored-by: Darrell Pappa <[email protected]>
Co-authored-by: mitch-hamm <[email protected]>
Co-authored-by: Yisheng Cai <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Nov 12, 2024
1 parent 50f5d5c commit 5008783
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 461 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "TF GH Action"
name: Terraform

on:
- pull_request

Expand All @@ -11,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1.3.2
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.1.x
terraform_version: "1.5.5"

- name: Terraform fmt
run: terraform fmt -recursive -write=false -check -diff .
Expand All @@ -27,21 +28,21 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
terraform_version: [1.1.x]
terraform_version: ["1.5.5"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Terraform ${{ matrix.terraform_version }}
uses: hashicorp/setup-terraform@v1.3.2
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform_version }}

- name: Terraform Validate Root
run: cd "${GITHUB_WORKSPACE}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate -no-color
run: cd "${GITHUB_WORKSPACE}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate

- name: Terraform Validate Modules
run: for module in modules/*/; do cd "${GITHUB_WORKSPACE}/${module}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate -no-color ; done
run: for module in modules/*/; do cd "${GITHUB_WORKSPACE}/${module}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate; done

- name: Terraform Validate Examples
run: for example in examples/*/; do cd "${GITHUB_WORKSPACE}/${example}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate -no-color ; done
run: for example in examples/*/; do cd "${GITHUB_WORKSPACE}/${example}" && terraform init -backend=false && AWS_REGION=us-east-1 terraform validate; done
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ A bare minimum configuration to execute the module:

```hcl
data "aws_eks_cluster" "cluster" {
name = module.eks_cluster.eks_cluster_id
name = module.eks_cluster.eks_cluster_name
}
data "aws_eks_cluster_auth" "cluster" {
name = module.eks_cluster.eks_cluster_id
name = module.eks_cluster.eks_cluster_name
}
provider "aws" {
Expand Down Expand Up @@ -168,24 +168,25 @@ _Note: Since this module manages all of the Kubernetes addon dependencies requir

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >=3.61.0 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | 2.2.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >=2.6.1 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.75 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.16 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.32 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.71.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.16.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.75.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.16.1 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.33.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | 18.30.2 |
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | 20.29.0 |
| <a name="module_eks_auth"></a> [eks\_auth](#module\_eks\_auth) | terraform-aws-modules/eks/aws//modules/aws-auth | 20.29.0 |
| <a name="module_istio"></a> [istio](#module\_istio) | github.com/streamnative/terraform-helm-charts//modules/istio-operator | v0.8.6 |
| <a name="module_vpc_tags"></a> [vpc\_tags](#module\_vpc\_tags) | ./modules/eks-vpc-tags | n/a |

Expand Down Expand Up @@ -225,16 +226,16 @@ _Note: Since this module manages all of the Kubernetes addon dependencies requir
| [aws_s3_bucket.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.tiered_storage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [helm_release.aws_load_balancer_controller](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.cert_issuer](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.cert_manager](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.cilium](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.csi](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.external_dns](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.metrics_server](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.node_termination_handler](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.velero](https://registry.terraform.io/providers/hashicorp/helm/2.2.0/docs/resources/release) | resource |
| [helm_release.aws_load_balancer_controller](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.cert_issuer](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.cert_manager](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.cilium](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.csi](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.external_dns](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.metrics_server](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.node_termination_handler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.velero](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubernetes_namespace.sn_system](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
| [kubernetes_namespace.velero](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
| [kubernetes_storage_class.sn_default](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
Expand Down Expand Up @@ -393,10 +394,10 @@ _Note: Since this module manages all of the Kubernetes addon dependencies requir
| <a name="output_eks_cluster_arn"></a> [eks\_cluster\_arn](#output\_eks\_cluster\_arn) | The ARN for the EKS cluster created by this module |
| <a name="output_eks_cluster_certificate_authority_data"></a> [eks\_cluster\_certificate\_authority\_data](#output\_eks\_cluster\_certificate\_authority\_data) | Base64 encoded certificate data required to communicate with the cluster |
| <a name="output_eks_cluster_endpoint"></a> [eks\_cluster\_endpoint](#output\_eks\_cluster\_endpoint) | The endpoint for the EKS cluster created by this module |
| <a name="output_eks_cluster_id"></a> [eks\_cluster\_id](#output\_eks\_cluster\_id) | The id/name of the EKS cluster created by this module |
| <a name="output_eks_cluster_identity_oidc_issuer_arn"></a> [eks\_cluster\_identity\_oidc\_issuer\_arn](#output\_eks\_cluster\_identity\_oidc\_issuer\_arn) | The ARN for the OIDC issuer created by this module |
| <a name="output_eks_cluster_identity_oidc_issuer_string"></a> [eks\_cluster\_identity\_oidc\_issuer\_string](#output\_eks\_cluster\_identity\_oidc\_issuer\_string) | A formatted string containing the prefix for the OIDC issuer created by this module. Same as "cluster\_oidc\_issuer\_url", but with "https://" stripped from the name. This output is typically used in other StreamNative modules that request the "oidc\_issuer" input. |
| <a name="output_eks_cluster_identity_oidc_issuer_url"></a> [eks\_cluster\_identity\_oidc\_issuer\_url](#output\_eks\_cluster\_identity\_oidc\_issuer\_url) | The URL for the OIDC issuer created by this module |
| <a name="output_eks_cluster_name"></a> [eks\_cluster\_name](#output\_eks\_cluster\_name) | The name of the EKS cluster created by this module |
| <a name="output_eks_cluster_platform_version"></a> [eks\_cluster\_platform\_version](#output\_eks\_cluster\_platform\_version) | The platform version for the EKS cluster created by this module |
| <a name="output_eks_cluster_primary_security_group_id"></a> [eks\_cluster\_primary\_security\_group\_id](#output\_eks\_cluster\_primary\_security\_group\_id) | The id of the primary security group created by the EKS service itself, not by this module. This is labeled "Cluster Security Group" in the EKS console. |
| <a name="output_eks_cluster_secondary_security_group_id"></a> [eks\_cluster\_secondary\_security\_group\_id](#output\_eks\_cluster\_secondary\_security\_group\_id) | The id of the secondary security group created by this module. This is labled "Additional Security Groups" in the EKS console. |
Expand Down
8 changes: 6 additions & 2 deletions aws_load_balancer_controller.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

data "aws_iam_policy_document" "aws_load_balancer_controller" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"iam:CreateServiceLinkedRole",
Expand Down Expand Up @@ -237,6 +239,8 @@ data "aws_iam_policy_document" "aws_load_balancer_controller" {
}

data "aws_iam_policy_document" "aws_load_balancer_controller_sts" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"sts:AssumeRoleWithWebIdentity"
Expand All @@ -258,7 +262,7 @@ resource "aws_iam_role" "aws_load_balancer_controller" {
count = var.enable_resource_creation ? 1 : 0
name = format("%s-lbc-role", module.eks.cluster_id)
description = format("Role used by IRSA and the KSA aws-load-balancer-controller on StreamNative Cloud EKS cluster %s", module.eks.cluster_id)
assume_role_policy = data.aws_iam_policy_document.aws_load_balancer_controller_sts.json
assume_role_policy = data.aws_iam_policy_document.aws_load_balancer_controller_sts.0.json
path = "/StreamNative/"
permissions_boundary = var.permissions_boundary_arn
tags = local.tags
Expand All @@ -275,7 +279,7 @@ resource "aws_iam_policy" "aws_load_balancer_controller" {
name = format("%s-AWSLoadBalancerControllerPolicy", module.eks.cluster_id)
description = "Policy that defines the permissions for the AWS Load Balancer Controller addon service running in a StreamNative Cloud EKS cluster"
path = "/StreamNative/"
policy = data.aws_iam_policy_document.aws_load_balancer_controller.json
policy = data.aws_iam_policy_document.aws_load_balancer_controller.0.json
tags = local.tags
}

Expand Down
8 changes: 6 additions & 2 deletions cert_manager.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

data "aws_iam_policy_document" "cert_manager" {
count = var.enable_resource_creation ? 1 : 0

statement {
sid = "Changes"
actions = [
Expand Down Expand Up @@ -49,6 +51,8 @@ data "aws_iam_policy_document" "cert_manager" {
}

data "aws_iam_policy_document" "cert_manager_sts" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"sts:AssumeRoleWithWebIdentity"
Expand All @@ -70,7 +74,7 @@ resource "aws_iam_role" "cert_manager" {
count = var.enable_resource_creation ? 1 : 0
name = format("%s-cm-role", module.eks.cluster_id)
description = format("Role assumed by IRSA and the KSA cert-manager on StreamNative Cloud EKS cluster %s", module.eks.cluster_id)
assume_role_policy = data.aws_iam_policy_document.cert_manager_sts.json
assume_role_policy = data.aws_iam_policy_document.cert_manager_sts.0.json
path = "/StreamNative/"
permissions_boundary = var.permissions_boundary_arn
tags = local.tags
Expand All @@ -87,7 +91,7 @@ resource "aws_iam_policy" "cert_manager" {
name = format("%s-CertManagerPolicy", module.eks.cluster_id)
description = "Policy that defines the permissions for the Cert-Manager addon service running in a StreamNative Cloud EKS cluster"
path = "/StreamNative/"
policy = data.aws_iam_policy_document.cert_manager.json
policy = data.aws_iam_policy_document.cert_manager.0.json
tags = local.tags
}

Expand Down
8 changes: 6 additions & 2 deletions cluster_autoscaler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

data "aws_iam_policy_document" "cluster_autoscaler" {
count = var.enable_resource_creation ? 1 : 0

statement {
effect = "Allow"

Expand Down Expand Up @@ -51,6 +53,8 @@ data "aws_iam_policy_document" "cluster_autoscaler" {
}

data "aws_iam_policy_document" "cluster_autoscaler_sts" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"sts:AssumeRoleWithWebIdentity"
Expand All @@ -77,7 +81,7 @@ resource "aws_iam_role" "cluster_autoscaler" {
count = var.enable_resource_creation ? 1 : 0
name = format("%s-ca-role", module.eks.cluster_id)
description = format("Role used by IRSA and the KSA cluster-autoscaler on StreamNative Cloud EKS cluster %s", module.eks.cluster_id)
assume_role_policy = data.aws_iam_policy_document.cluster_autoscaler_sts.json
assume_role_policy = data.aws_iam_policy_document.cluster_autoscaler_sts.0.json
path = "/StreamNative/"
permissions_boundary = var.permissions_boundary_arn
tags = local.tags
Expand All @@ -94,7 +98,7 @@ resource "aws_iam_policy" "cluster_autoscaler" {
name = format("%s-ClusterAutoscalerPolicy", module.eks.cluster_id)
description = "Policy that defines the permissions for the Cluster Autoscaler addon service running in a StreamNative Cloud EKS cluster"
path = "/StreamNative/"
policy = data.aws_iam_policy_document.cluster_autoscaler.json
policy = data.aws_iam_policy_document.cluster_autoscaler.0.json
tags = local.tags
}

Expand Down
8 changes: 6 additions & 2 deletions csi.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

data "aws_iam_policy_document" "csi" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"ec2:CreateSnapshot",
Expand Down Expand Up @@ -142,6 +144,8 @@ data "aws_iam_policy_document" "csi" {
}

data "aws_iam_policy_document" "csi_sts" {
count = var.enable_resource_creation ? 1 : 0

statement {
actions = [
"sts:AssumeRoleWithWebIdentity"
Expand All @@ -168,7 +172,7 @@ resource "aws_iam_role" "csi" {
count = var.enable_resource_creation ? 1 : 0
name = format("%s-csi-role", module.eks.cluster_id)
description = format("Role used by IRSA and the KSA ebs-csi-controller-sa on StreamNative Cloud EKS cluster %s", module.eks.cluster_id)
assume_role_policy = data.aws_iam_policy_document.csi_sts.json
assume_role_policy = data.aws_iam_policy_document.csi_sts.0.json
path = "/StreamNative/"
permissions_boundary = var.permissions_boundary_arn
tags = local.tags
Expand All @@ -185,7 +189,7 @@ resource "aws_iam_policy" "csi" {
name = format("%s-CsiPolicy", module.eks.cluster_id)
description = "Policy that defines the permissions for the EBS Container Storage Interface CSI addon service running in a StreamNative Cloud EKS cluster"
path = "/StreamNative/"
policy = data.aws_iam_policy_document.csi.json
policy = data.aws_iam_policy_document.csi.0.json
tags = local.tags
}

Expand Down
Loading

0 comments on commit 5008783

Please sign in to comment.