Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e test update #164

Merged
merged 10 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Terraform Init
id: init
run: terraform init
run: terraform init -backend-config backend.conf -reconfigure
working-directory: test/e2e/eks
continue-on-error: false

Expand All @@ -55,20 +55,20 @@ jobs:
- name: Terraform Plan
id: plan
working-directory: test/e2e/eks
run: terraform plan -no-color
run: terraform plan -var-file base.tfvars -no-color
continue-on-error: false

- name: Terraform Apply
id: apply
working-directory: test/e2e/eks
run: terraform apply -no-color -auto-approve
run: terraform apply -var-file base.tfvars -no-color -auto-approve
continue-on-error: true

- name: Terraform Destroy
if: github.event.inputs.TFDestroy == 'true' && (steps.apply.outcome == 'success' || steps.apply.outcome == 'failure')
id: destroy
working-directory: test/e2e/eks
run: terraform destroy -no-color -auto-approve
run: terraform destroy -var-file base.tfvars -no-color -auto-approve
continue-on-error: false

- name: Fail if TF apply failed
Expand All @@ -78,4 +78,4 @@ jobs:
echo "Terraform Apply step failed...Please check the logs of the Terraform Apply step."
echo "Failing the job to avoid false positives."
exit 1
continue-on-error: false
continue-on-error: false
6 changes: 3 additions & 3 deletions .github/workflows/vpc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Terraform Init
id: init
run: terraform init
run: terraform init -backend-config backend.conf -reconfigure
working-directory: test/e2e/vpc
continue-on-error: false

Expand All @@ -50,11 +50,11 @@ jobs:
- name: Terraform Plan
id: plan
working-directory: test/e2e/vpc
run: terraform plan -no-color
run: terraform plan -var-file base.tfvars -no-color
continue-on-error: false

- name: Terraform Apply
id: apply
working-directory: test/e2e/vpc
run: terraform apply -no-color -auto-approve
run: terraform apply -var-file base.tfvars -no-color -auto-approve
continue-on-error: false
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ repos:
hooks:
- id: trailing-whitespace
args: ['--markdown-linebreak-ext=md']
- id: check-yaml
exclude: '[\w\-\/]+/templates/'
- id: end-of-file-fixer
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, main]
- id: detect-private-key
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
Expand Down
20 changes: 8 additions & 12 deletions deploy/2-eks-cluster-with-import-vpc/eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.66.0 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.7.1 |
No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.66.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
| <a name="provider_terraform"></a> [terraform](#provider\_terraform) | n/a |

## Modules

Expand All @@ -43,20 +39,20 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

| Name | Type |
|------|------|
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_eks_cluster.cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
| [aws_eks_cluster_auth.cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [terraform_remote_state.vpc_s3_backend](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_environment"></a> [environment](#input\_environment) | Environment area, e.g. prod or preprod | `string` | `"preprod"` | no |
| <a name="input_private_subnet_ids"></a> [private\_subnet\_ids](#input\_private\_subnet\_ids) | list of private subnets Id's for the Worker nodes | `list(string)` | n/a | yes |
| <a name="input_public_subnet_ids"></a> [public\_subnet\_ids](#input\_public\_subnet\_ids) | list of public subnets Id's for the Worker nodes | `list(string)` | `[]` | no |
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes Version | `string` | `"1.21"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | n/a | yes |
| <a name="input_tenant"></a> [tenant](#input\_tenant) | Account Name or unique account unique id e.g., apps or management or aws007 | `string` | `"aws"` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC id | `string` | n/a | yes |
| <a name="input_tf_state_vpc_s3_bucket"></a> [tf\_state\_vpc\_s3\_bucket](#input\_tf\_state\_vpc\_s3\_bucket) | Terraform state S3 Bucket Name | `string` | n/a | yes |
| <a name="input_tf_state_vpc_s3_key"></a> [tf\_state\_vpc\_s3\_key](#input\_tf\_state\_vpc\_s3\_key) | Terraform state S3 Key path | `string` | n/a | yes |
| <a name="input_zone"></a> [zone](#input\_zone) | zone, e.g. dev or qa or load or ops etc... | `string` | `"test"` | no |

## Outputs
Expand Down
98 changes: 30 additions & 68 deletions deploy/2-eks-cluster-with-import-vpc/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,58 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

terraform {
required_version = ">= 1.0.1"
provider "aws" {
region = var.region
}

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.66.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.7.1"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.4.1"
}
provider "kubernetes" {
experiments {
manifest_resource = true
}
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
token = data.aws_eks_cluster_auth.cluster.token
}

provider "aws" {
region = "us-west-2"
alias = "default"
provider "helm" {
kubernetes {
host = data.aws_eks_cluster.cluster.endpoint
token = data.aws_eks_cluster_auth.cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
}
}

data "aws_region" "current" {}
data "aws_eks_cluster" "cluster" {
name = module.aws-eks-accelerator-for-terraform.eks_cluster_id
}

data "aws_availability_zones" "available" {}
data "aws_eks_cluster_auth" "cluster" {
name = module.aws-eks-accelerator-for-terraform.eks_cluster_id
}

#---------------------------------------------------------------
# Note: Terraform_remote_state for S3 backend can be imported using the below code snippet
# Terraform VPC remote state import from S3
#---------------------------------------------------------------
/*
data "terraform_remote_state" "vpc_s3_backend" {
backend = "s3"
config = {
bucket = "" # Bucket name
key = "" # Key path to terraform-main.tfstate file
region = "" # aws region
bucket = var.tf_state_vpc_s3_bucket
key = var.tf_state_vpc_s3_key
region = var.region
}

vpc_id = data.terraform_remote_state.vpc_s3_backend.outputs.vpc_id
private_subnet_ids = data.terraform_remote_state.vpc_s3_backend.outputs.private_subnets
public_subnet_ids = data.terraform_remote_state.vpc_s3_backend.outputs.public_subnets

}*/
}

locals {
tenant = var.tenant
environment = var.environment
zone = var.zone

kubernetes_version = "1.21"
kubernetes_version = var.kubernetes_version
terraform_version = "Terraform v1.0.1"

vpc_id = var.vpc_id
private_subnet_ids = var.private_subnet_ids
public_subnet_ids = var.public_subnet_ids
vpc_id = data.terraform_remote_state.vpc_s3_backend.outputs.vpc_id
private_subnet_ids = data.terraform_remote_state.vpc_s3_backend.outputs.private_subnets
public_subnet_ids = data.terraform_remote_state.vpc_s3_backend.outputs.public_subnets
}

module "aws-eks-accelerator-for-terraform" {
Expand Down Expand Up @@ -101,46 +96,13 @@ module "aws-eks-accelerator-for-terraform" {
}
}

data "aws_eks_cluster" "cluster" {
name = module.aws-eks-accelerator-for-terraform.eks_cluster_id
}

data "aws_eks_cluster_auth" "cluster" {
name = module.aws-eks-accelerator-for-terraform.eks_cluster_id
}

provider "kubernetes" {
experiments {
manifest_resource = true
}
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
token = data.aws_eks_cluster_auth.cluster.token
}

provider "helm" {
kubernetes {
host = data.aws_eks_cluster.cluster.endpoint
token = data.aws_eks_cluster_auth.cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
}
}


module "kubernetes-addons" {
providers = {
kubernetes = kubernetes
helm = helm
aws = aws.default
}

source = "../../../modules/kubernetes-addons"

eks_cluster_id = module.aws-eks-accelerator-for-terraform.eks_cluster_id
eks_oidc_issuer_url = module.aws-eks-accelerator-for-terraform.eks_oidc_issuer_url
eks_oidc_provider_arn = module.aws-eks-accelerator-for-terraform.eks_oidc_provider_arn
eks_worker_security_group_id = module.aws-eks-accelerator-for-terraform.worker_security_group_id
auto_scaling_group_names = module.aws-eks-accelerator-for-terraform.self_managed_node_group_autoscaling_groups

# EKS Managed Add-ons
enable_amazon_eks_vpc_cni = true
Expand Down
38 changes: 21 additions & 17 deletions deploy/2-eks-cluster-with-import-vpc/eks/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
variable "kubernetes_version" {
type = string
description = "Kubernetes Version"
default = "1.21"
}

variable "region" {
type = string
description = "AWS region"
}

variable "tf_state_vpc_s3_bucket" {
type = string
description = "Terraform state S3 Bucket Name"
}

variable "tf_state_vpc_s3_key" {
type = string
description = "Terraform state S3 Key path"
}

variable "tenant" {
type = string
description = "Account Name or unique account unique id e.g., apps or management or aws007"
Expand All @@ -15,20 +36,3 @@ variable "zone" {
description = "zone, e.g. dev or qa or load or ops etc..."
default = "test"
}

# VPC Config for EKS Cluster
variable "vpc_id" {
type = string
description = "VPC id"
}

variable "private_subnet_ids" {
description = "list of private subnets Id's for the Worker nodes"
type = list(string)
}

variable "public_subnet_ids" {
description = "list of public subnets Id's for the Worker nodes"
type = list(string)
default = []
}
18 changes: 9 additions & 9 deletions deploy/2-eks-cluster-with-import-vpc/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.66.0 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.6.1 |
No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.66.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

Expand All @@ -43,11 +38,16 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Name | Type |
|------|------|
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_environment"></a> [environment](#input\_environment) | Environment area, e.g. prod or preprod | `string` | `"preprod"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | n/a | yes |
| <a name="input_tenant"></a> [tenant](#input\_tenant) | Account Name or unique account unique id e.g., apps or management or aws007 | `string` | `"aws"` | no |
| <a name="input_vpc_cidr"></a> [vpc\_cidr](#input\_vpc\_cidr) | VPC CIDR range | `string` | `"10.1.0.0/16"` | no |
| <a name="input_zone"></a> [zone](#input\_zone) | zone, e.g. dev or qa or load or ops etc... | `string` | `"test"` | no |

## Outputs

Expand Down
32 changes: 5 additions & 27 deletions deploy/2-eks-cluster-with-import-vpc/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,18 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

terraform {
required_version = ">= 1.0.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.66.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.6.1"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.4.1"
}
}
}

provider "aws" {
region = data.aws_region.current.id
alias = "default"
region = var.region
}

data "aws_region" "current" {}

data "aws_availability_zones" "available" {}

locals {
tenant = "aws001" # AWS account name or unique id for tenant
environment = "preprod" # Environment area eg., preprod or prod
zone = "test" # Environment with in one sub_tenant or business unit
tenant = var.tenant
environment = var.environment
zone = var.zone

vpc_cidr = "10.1.0.0/16"
vpc_cidr = var.vpc_cidr
vpc_name = join("-", [local.tenant, local.environment, local.zone, "vpc"])
eks_cluster_id = join("-", [local.tenant, local.environment, local.zone, "eks"])

Expand Down
Loading