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

fix: explicitly set fallback values for ssh key and admin password #72

Merged
merged 2 commits into from
Jul 1, 2024
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
71 changes: 71 additions & 0 deletions examples/authentication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
This module enables flexible kubernetes cluster setup by supporting both auto generated and user supplied (bring your own) ssh keys and passwords for tailored access.

## Usage: generated password or ssh key

To utilize the generated password or ssh key, simply specify the key vault id in your configuration:

```hcl
module "aks" {
source = "cloudnationhq/aks/azure"
version = "~> 0.1"

keyvault = module.kv.vault.id

cluster = {
name = module.naming.kubernetes_cluster.name_unique
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name
depends_on = [module.kv]
profile = "linux"
dns_prefix = "demo"
}
}
```

## Usage: bringing your own password or ssh key

To use your own password or SSH key, use the below properties in your configuration:

```hcl
module "aks-linux" {
source = "cloudnationhq/aks/azure"
version = "~> 0.1"

cluster = {
name = "${module.naming.kubernetes_cluster.name}-02"
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name
node_resourcegroup = "${module.rg.groups.demo.name}-node02"
depends_on = [module.kv]
profile = "linux"
dns_prefix = "demo2"
sku_tier = "Standard"

public_key = module.kv.tls_public_keys.tls.value
}
}
```

```hcl
module "aks-windows" {
source = "cloudnationhq/aks/azure"
version = "~> 0.1"

cluster = {
name = "${module.naming.kubernetes_cluster.name}-01"
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name
node_resourcegroup = "${module.rg.groups.demo.name}-node01"
depends_on = [module.kv]
profile = "windows"
dns_prefix = "demo1"
sku_tier = "Standard"

network_profile = {
network_plugin = "azure"
}

password = module.kv.secrets.password.value
}
}
```
8 changes: 8 additions & 0 deletions examples/authentication/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
naming = {
# lookup outputs to have consistent naming
for type in local.naming_types : type => lookup(module.naming, type).name
}

naming_types = ["key_vault_secret"]
}
86 changes: 86 additions & 0 deletions examples/authentication/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module "naming" {
source = "cloudnationhq/naming/azure"
version = "~> 0.1"

suffix = ["demo", "dev"]
}

module "rg" {
source = "cloudnationhq/rg/azure"
version = "~> 0.1"

groups = {
demo = {
name = module.naming.resource_group.name
region = "westeurope"
}
}
}

module "kv" {
source = "cloudnationhq/kv/azure"
version = "~> 0.1"

naming = local.naming

vault = {
name = module.naming.key_vault.name_unique
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name

secrets = {
tls_keys = {
tls = {
algorithm = "RSA"
key_size = 2048
}
}
random_string = {
password = {
length = 24
special = false
}
}
}
}
}

module "aks-windows" {
source = "cloudnationhq/aks/azure"
version = "~> 0.1"

cluster = {
name = "${module.naming.kubernetes_cluster.name}-01"
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name
node_resourcegroup = "${module.rg.groups.demo.name}-node01"
depends_on = [module.kv]
profile = "windows"
dns_prefix = "demo1"
sku_tier = "Standard"

network_profile = {
network_plugin = "azure"
}

password = module.kv.secrets.password.value
}
}

module "aks-linux" {
source = "cloudnationhq/aks/azure"
version = "~> 0.1"

cluster = {
name = "${module.naming.kubernetes_cluster.name}-02"
location = module.rg.groups.demo.location
resourcegroup = module.rg.groups.demo.name
node_resourcegroup = "${module.rg.groups.demo.name}-node02"
depends_on = [module.kv]
profile = "linux"
dns_prefix = "demo2"
sku_tier = "Standard"

public_key = module.kv.tls_public_keys.tls.value
}
}
22 changes: 22 additions & 0 deletions examples/authentication/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_version = "~> 1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.61"
}
tls = {
source = "hashicorp/tls"
version = "~> 4.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}

provider "azurerm" {
features {}
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ resource "azurerm_kubernetes_cluster" "aks" {

content {
admin_username = try(var.cluster.username, "nodeadmin")
admin_password = try(var.cluster.password, azurerm_key_vault_secret.secret[windows_profile.key].value)
admin_password = try(var.cluster.password, null) != null ? var.cluster.password : azurerm_key_vault_secret.secret["default"].value
}
}

Expand All @@ -209,7 +209,7 @@ resource "azurerm_kubernetes_cluster" "aks" {
content {
admin_username = try(var.cluster.username, "nodeadmin")
ssh_key {
key_data = try(var.cluster.public_key, tls_private_key.tls_key[var.cluster.name].public_key_openssh)
key_data = try(var.cluster.public_key, null) != null ? var.cluster.public_key : tls_private_key.tls_key["default"].public_key_openssh
}
}
}
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ variable "cluster" {
variable "keyvault" {
description = "keyvault to store secrets"
type = string
default = null
}

variable "location" {
Expand Down
Loading