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

support deploying on existing vpc on aws #1807

Merged
merged 6 commits into from
May 18, 2023
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
2 changes: 1 addition & 1 deletion nebari/stages/input_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def stage_02_infrastructure(stage_outputs, config):
"kubeconfig_filename": os.path.join(
tempfile.gettempdir(), "NEBARI_KUBECONFIG"
),
**config.get("aws", {}).get("terraform_overrides", {}),
**config.get("amazon_web_services", {}).get("terraform_overrides", {}),
Copy link
Member Author

@Adam-D-Lewis Adam-D-Lewis May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These terraform overrides were not usable before as far as I can tell. You'd get an error from pydantic that extra fields (the aws field) weren't allowed when I added an aws section to the nebari-config.yaml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now they can be used via (e.g.)

amazon_web_services:
  terraform_overrides:
    existing_subnet_ids: ["subnet-05b2b1f41f0b1d8a6", "subnet-017efc3309fbca2da"]
    existing_security_group_id: "sg-0e2c865bdd8824b1a"
  region: ...
  <other_attributes>: ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth formalizing these the available terraform_overrides in the schema?

}
else:
return {}
Expand Down
21 changes: 14 additions & 7 deletions nebari/template/stages/02-infrastructure/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ data "aws_availability_zones" "awszones" {
}
}


locals {
# Only override_network if both existing_subnet_ids and existing_security_group_id are not null.
override_network = (var.existing_subnet_ids != null) && (var.existing_security_group_id != null)
subnet_ids = local.override_network ? var.existing_subnet_ids : module.network[0].subnet_ids
security_group_id = local.override_network ? var.existing_security_group_id : module.network[0].security_group_id
iameskild marked this conversation as resolved.
Show resolved Hide resolved
}

# ==================== ACCOUNTING ======================
module "accounting" {
source = "./modules/accounting"
Expand All @@ -18,6 +26,8 @@ module "accounting" {

# ======================= NETWORK ======================
module "network" {
count = local.override_network ? 0 : 1
iameskild marked this conversation as resolved.
Show resolved Hide resolved

source = "./modules/network"

name = local.cluster_name
Expand Down Expand Up @@ -57,8 +67,8 @@ module "efs" {
name = "${local.cluster_name}-jupyterhub-shared"
tags = local.additional_tags

efs_subnets = module.network.subnet_ids
efs_security_groups = [module.network.security_group_id]
efs_subnets = local.subnet_ids
efs_security_groups = [local.security_group_id]
}


Expand All @@ -71,16 +81,13 @@ module "kubernetes" {
region = var.region
kubernetes_version = var.kubernetes_version

cluster_subnets = module.network.subnet_ids
cluster_security_groups = [module.network.security_group_id]
cluster_subnets = local.subnet_ids
cluster_security_groups = [local.security_group_id]

node_group_additional_policies = [
"arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
]

node_groups = var.node_groups

depends_on = [
module.network
]
Adam-D-Lewis marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 12 additions & 0 deletions nebari/template/stages/02-infrastructure/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ variable "environment" {
type = string
}

variable "existing_subnet_ids" {
description = "Existing VPC ID to use for Kubernetes resources"
type = list(string)
default = null
}

variable "existing_security_group_id" {
description = "Existing security group ID to use for Kubernetes resources"
type = string
default = null
}

variable "region" {
description = "AWS region for EKS cluster"
type = string
Expand Down