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

Features/allow existing subnet #99

Closed
Closed
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
20 changes: 20 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform-Module.gitlab-ci.yml

include:
Copy link
Member

Choose a reason for hiding this comment

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

The pipelines are currently running on Github actions. Could you please remove this?

Copy link
Member

Choose a reason for hiding this comment

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

I'll kick of the pipeline for this changes

Copy link
Author

Choose a reason for hiding this comment

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

I did this in a hurry. I'll finish my work a submit a larger PR with proper care.

Copy link
Member

Choose a reason for hiding this comment

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

@yves-vogl no worries let us know if you have any questions

- template: Terraform/Module-Base.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Module-Base.gitlab-ci.yml
- template: Jobs/SAST-IaC.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Jobs/SAST-IaC.gitlab-ci.yml

stages:
- validate
- build
- test
- deploy

# See the included job template at `Terraform/Module-Base.gitlab-ci.yml` to learn about supported variables.
deploy:
extends: .terraform-module:deploy
rules:
- if: $CI_COMMIT_TAG
12 changes: 11 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ locals {
}
}
}
}
}

# Helper locals to DRY'up conditionals
locals {
vnet_subnet_id = (var.node_subnet != null
? var.node_subnet
: module.avm_res_network_virtualnetwork[0].subnets["subnet"].resource_id
)


}
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resource "azurerm_kubernetes_cluster" "this" {
orchestrator_version = var.orchestrator_version
os_sku = "Ubuntu"
tags = merge(var.tags, var.agents_tags)
vnet_subnet_id = module.avm_res_network_virtualnetwork.subnets["subnet"].resource_id
vnet_subnet_id = local.vnet_subnet_id
zones = try([for zone in local.regions_by_name_or_display_name[var.location].zones : zone], null)

upgrade_settings {
Expand Down Expand Up @@ -239,7 +239,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "this" {
orchestrator_version = each.value.orchestrator_version
os_sku = each.value.os_sku
tags = var.tags
vnet_subnet_id = module.avm_res_network_virtualnetwork.subnets["subnet"].resource_id
vnet_subnet_id = local.vnet_subnet_id
zones = each.value.zone == "" ? null : [each.value.zone]

depends_on = [azapi_update_resource.aks_cluster_post_create]
Expand Down Expand Up @@ -271,6 +271,8 @@ module "avm_res_network_virtualnetwork" {
source = "Azure/avm-res-network-virtualnetwork/azurerm"
version = "0.2.3"

count = var.node_subnet == null ? 1 : 0

address_space = var.node_cidr != null ? [var.node_cidr] : ["10.31.0.0/16"]
location = var.location
name = var.virtual_network_name
Expand All @@ -282,3 +284,5 @@ module "avm_res_network_virtualnetwork" {
}
}
}


6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ variable "node_cidr" {
description = "(Optional) The CIDR to use for node IPs in the Kubernetes cluster. Changing this forces a new resource to be created."
}

variable "node_subnet" {
type = string
default = null
description = "(Optional) The resource id of the existing subnet to use for node IPs in the Kubernetes cluster. Changing this forces a new resource to be created."
}

variable "node_pools" {
type = map(object({
name = string
Expand Down
Loading