Skip to content

Commit

Permalink
feat: Create cluster in existing VPC (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
msvticket authored Jun 7, 2021
1 parent a9924e8 commit a609ea2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ The following sections provide a full list of configuration in- and output varia
| single\_nat\_gateway | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | `bool` | `false` | no |
| spot\_price | The spot price ceiling for spot instances | `string` | `"0.1"` | no |
| subdomain | The subdomain to be added to the apex domain. If subdomain is set, it will be appended to the apex domain in `jx-requirements-eks.yml` file | `string` | `""` | no |
| subnets | The subnet ids to create EKS cluster in if create\_vpc is false | `list(string)` | `[]` | no |
| tls\_email | The email to register the LetsEncrypt certificate with. Added to the `jx-requirements.yml` file | `string` | `""` | no |
| use\_asm | Flag to specify if AWS Secrets manager is being used | `bool` | `false` | no |
| use\_kms\_s3 | Flag to determine whether kms should be used for encrypting s3 buckets | `bool` | `false` | no |
Expand All @@ -238,6 +239,7 @@ The following sections provide a full list of configuration in- and output varia
| volume\_size | The volume size in GB | `number` | `50` | no |
| volume\_type | The volume type to use. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
| vpc\_cidr\_block | The vpc CIDR block | `string` | `"10.0.0.0/16"` | no |
| vpc\_id | The VPC to create EKS cluster in if create\_vpc is false | `string` | `""` | no |
| vpc\_name | The name of the VPC to be created for the cluster | `string` | `"tf-vpc-eks"` | no |

#### Outputs
Expand Down Expand Up @@ -742,6 +744,11 @@ You need to execute the following command before `terraform apply` in order to r
Creation of namespaces and service accounts using terraform is no longer required for JX3.
To keep compatibility with JX2, a flag `is_jx2` was introduced, in [v1.6.0](https://github.com/jenkins-x/terraform-aws-eks-jx/releases/tag/v1.6.0).

### Existing VPC

If you want to create the cluster in an existing VPC you can specify `create_vpc` to false and
specify where to create the clsuter with `vpc_id` and `subnets`.

### Existing EKS cluster
It is very common to have another module used to create EKS clusters for all your AWS accounts, in that case, you can
set `create_eks` and `create_vpc` to false and `cluster_name` to the id/name of the EKS cluster where jx components
Expand Down
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module "cluster" {
region = var.region
create_eks = var.create_eks
create_vpc = var.create_vpc
vpc_id = var.vpc_id
subnets = var.subnets
cluster_name = local.cluster_name
cluster_version = var.cluster_version
desired_node_count = var.desired_node_count
Expand Down
6 changes: 3 additions & 3 deletions modules/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ module "eks" {
create_eks = var.create_eks
cluster_name = var.cluster_name
cluster_version = var.cluster_version
subnets = (var.cluster_in_private_subnet ? module.vpc.private_subnets : module.vpc.public_subnets)
vpc_id = module.vpc.vpc_id
subnets = var.create_vpc ? (var.cluster_in_private_subnet ? module.vpc.private_subnets : module.vpc.public_subnets) : var.subnets
vpc_id = var.create_vpc ? module.vpc.vpc_id : var.vpc_id
enable_irsa = true

worker_groups_launch_template = var.enable_worker_group && var.enable_worker_groups_launch_template ? [
for subnet in module.vpc.public_subnets :
for subnet in (var.create_vpc ? module.vpc.public_subnets : var.subnets) :
{
subnets = [subnet]
asg_desired_capacity = var.lt_desired_nodes_per_subnet
Expand Down
12 changes: 12 additions & 0 deletions modules/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ variable "create_vpc" {
default = true
}

variable "vpc_id" {
description = "The VPC to create EKS cluster in if create_vpc is false"
type = string
default = ""
}

variable "subnets" {
description = "The subnet ids to create EKS cluster in if create_vpc is false"
type = list(string)
default = []
}

variable "encrypt_volume_self" {
description = "Encrypt the ebs and root volume for the self managed worker nodes. This is only valid for the worker group launch template"
type = bool
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,18 @@ variable "create_vpc" {
default = true
}

variable "vpc_id" {
description = "The VPC to create EKS cluster in if create_vpc is false"
type = string
default = ""
}

variable "subnets" {
description = "The subnet ids to create EKS cluster in if create_vpc is false"
type = list(string)
default = []
}

variable "use_vault" {
description = "Flag to control vault resource creation"
type = bool
Expand Down

0 comments on commit a609ea2

Please sign in to comment.