Skip to content

Commit

Permalink
Terraform consolidate keyvault (#1484)
Browse files Browse the repository at this point in the history
* Consolidate keyvault into common

* updates

---------

Co-authored-by: Automatic Update <radix@statoilsrm.onmicrosoft.com>
  • Loading branch information
sveinpj and Automatic Update authored Oct 28, 2024
1 parent 69d607d commit 382d9d7
Show file tree
Hide file tree
Showing 41 changed files with 412 additions and 962 deletions.
3 changes: 1 addition & 2 deletions scripts/aks/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ fi

printf "Initializing Terraform..."
terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/common" init
terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/virtualnetwork" init
terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/pre-clusters" init
terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/clusters" init
terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/post-clusters" init
Expand Down Expand Up @@ -349,7 +348,7 @@ fi
# if migrating active to active cluster (eg. dev to dev)
if [ "$MIGRATION_STRATEGY" = "aa" ]; then
# Path to Public IP Prefix which contains the public outbound IPs
IPPRE=$(terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/virtualnetwork" output -json public_ip_prefix_ids)
IPPRE=$(terraform -chdir="../terraform/subscriptions/$AZ_SUBSCRIPTION_NAME/$RADIX_ZONE/common" output -json public_ip_prefix_ids)
IPPRE_EGRESS_ID=$(jq -n "${IPPRE}" | jq -r .egress_id)
IPPRE_INGRESS_ID=$(jq -n "${IPPRE}" | jq -r .ingress_id)
# IPPRE_EGRESS_ID="/subscriptions/$AZ_SUBSCRIPTION_ID/resourceGroups/$AZ_RESOURCE_GROUP_IPPRE/providers/Microsoft.Network/publicIPPrefixes/$AZ_IPPRE_OUTBOUND_NAME"
Expand Down
2 changes: 1 addition & 1 deletion terraform/subscriptions/modules/key-vault/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "azurerm_role_assignment" "this" {

data "azurerm_subnet" "subnet" {
name = "private-links"
virtual_network_name = var.virtual_network
virtual_network_name = "vnet-hub"
resource_group_name = var.vnet_resource_group
}

Expand Down
77 changes: 1 addition & 76 deletions terraform/subscriptions/modules/key-vault/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
variable "tenant_id" {
description = "Tenant ID"
type = string

}

variable "vault_name" {
Expand All @@ -19,27 +18,10 @@ variable "location" {
type = string
}

variable "soft_delete_retention_days" {
description = "The number of days that items should be retained for once soft-deleted."
type = number
default = 90
}

variable "purge_protection_enabled" {
description = "Is purge protection enabled for this Key vault?"
type = bool
default = false
}

variable "access_policies" {
description = "A list of access policies for this Key vault."
type = list(object({
object_id = string
secret_permissions = optional(list(string), [])
certificate_permissions = optional(list(string), [])
key_permissions = optional(list(string), [])
}))
default = []
default = true
}

variable "enable_rbac_authorization" {
Expand All @@ -54,63 +36,6 @@ variable "kv_secrets_user_id" {
default = ""
}

variable "public_network_access_enabled" {
description = "Should public network access be enabled for this Key Vault?"
type = bool
default = true
}

variable "network_acls_default_action" {
description = "The default action of the network ACLs of this Key Vault."
type = string
default = "Deny"

validation {
condition = contains(["Allow", "Deny"], var.network_acls_default_action)
error_message = "Default action must be \"Allow\" or \"Deny\"."
}
}

variable "network_acls_bypass_azure_services" {
description = "Should Azure services be allowed to bypass the network ACLs of this Key Vault?."
type = bool
default = true
}

variable "network_acls_ip_rules" {
description = "A list of IP addresses or CIDR blocks that should be able to bypass the network ACL and access this Key vault."
type = list(string)
default = []
}

variable "network_acls_virtual_network_subnet_ids" {
description = "A list of Virtual Network subnet IDs that should be able to bypass the network ACL and access this Key vault."
type = list(string)
default = []
}

variable "diagnostic_setting_name" {
description = "The name of this diagnostic setting."
type = string
default = "audit-logs"
}

variable "diagnostic_setting_enabled_log_categories" {
description = "A list of log categories to be enabled for this diagnostic setting."
type = list(string)
default = ["AuditEvent"]
}

variable "tags" {
description = "A map of tags to assign to the resources."
type = map(string)
default = {}
}

variable "virtual_network" {
type = string
default = "vnet-hub"
}
variable "vnet_resource_group" {
type = string
}
Expand Down
16 changes: 16 additions & 0 deletions terraform/subscriptions/s940/c2/common/keyvault.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "azurerm_subscription" "current" {}

data "azurerm_key_vault_secret" "this" {
name = "storageaccounts-ip-rule"
key_vault_id = module.config.backend.ip_key_vault_id
}

module "keyvault" {
source = "../../../modules/key-vault"
location = module.config.location
vault_name = "radix-keyv-${module.config.environment}"
resource_group_name = module.config.common_resource_group
tenant_id = data.azurerm_subscription.current.tenant_id
vnet_resource_group = module.config.vnet_resource_group
ip_rule = data.azurerm_key_vault_secret.this.value
}
65 changes: 0 additions & 65 deletions terraform/subscriptions/s940/c2/common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,6 @@ module "config" {
source = "../../../modules/config"
}

###Migrated from 'Virtualnetwork' start

module "vnet_resourcegroup" {
source = "../../../modules/resourcegroups"
name = module.config.vnet_resource_group
location = module.config.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = module.config.location
enviroment = module.config.environment
vnet_resource_group = module.vnet_resourcegroup.data.name
private_dns_zones = tolist(module.config.private_dns_zones_names)
depends_on = [module.vnet_resourcegroup]

}

module "azurerm_public_ip_prefix_ingress" {
source = "../../../modules/network_publicipprefix"
location = module.config.location
resource_group_name = var.resource_groups_common_temporary #TODO
publicipprefixname = "ippre-ingress-radix-aks-${module.config.environment}-prod-001" #TODO
pipprefix = "ingress-radix-aks"
pippostfix = "prod"
enviroment = module.config.environment
prefix_length = 29
publicipcounter = 8
# zones = ["1", "2", "3"]
}

module "azurerm_public_ip_prefix_egress" {
source = "../../../modules/network_publicipprefix"
location = module.config.location
resource_group_name = var.resource_groups_common_temporary #TODO
publicipprefixname = "ippre-egress-radix-aks-${module.config.environment}-prod-001" #TODO
pipprefix = "egress-radix-aks"
pippostfix = "prod"
enviroment = module.config.environment
prefix_length = 29
publicipcounter = 8
}

output "vnet_hub_id" {
value = module.azurerm_virtual_network.data.vnet_hub.id
}

output "vnet_subnet_id" {
value = module.azurerm_virtual_network.data.vnet_subnet.id
}

output "public_ip_prefix_ids" {
value = {
egress_id = module.azurerm_public_ip_prefix_egress.data.id
ingress_id = module.azurerm_public_ip_prefix_ingress.data.id
}
}

###Migrated from 'Virtualnetwork' end

module "resourcegroups" {
source = "../../../modules/resourcegroups"
name = module.config.common_resource_group
Expand Down Expand Up @@ -91,11 +31,6 @@ data "azurerm_virtual_network" "this" {
resource_group_name = module.config.vnet_resource_group
}

data "azurerm_key_vault_secret" "this" {
name = "storageaccounts-ip-rule"
key_vault_id = module.config.backend.ip_key_vault_id
}

data "azurerm_subnet" "this" {
name = "private-links"
resource_group_name = module.config.vnet_resource_group
Expand Down
55 changes: 55 additions & 0 deletions terraform/subscriptions/s940/c2/common/virtualnetwork.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module "vnet_resourcegroup" {
source = "../../../modules/resourcegroups"
name = module.config.vnet_resource_group
location = module.config.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = module.config.location
enviroment = module.config.environment
vnet_resource_group = module.vnet_resourcegroup.data.name
private_dns_zones = tolist(module.config.private_dns_zones_names)
depends_on = [module.vnet_resourcegroup]

}

module "azurerm_public_ip_prefix_ingress" {
source = "../../../modules/network_publicipprefix"
location = module.config.location
resource_group_name = var.resource_groups_common_temporary #TODO
publicipprefixname = "ippre-ingress-radix-aks-${module.config.environment}-prod-001" #TODO
pipprefix = "ingress-radix-aks"
pippostfix = "prod"
enviroment = module.config.environment
prefix_length = 29
publicipcounter = 8
# zones = ["1", "2", "3"]
}

module "azurerm_public_ip_prefix_egress" {
source = "../../../modules/network_publicipprefix"
location = module.config.location
resource_group_name = var.resource_groups_common_temporary #TODO
publicipprefixname = "ippre-egress-radix-aks-${module.config.environment}-prod-001" #TODO
pipprefix = "egress-radix-aks"
pippostfix = "prod"
enviroment = module.config.environment
prefix_length = 29
publicipcounter = 8
}

output "vnet_hub_id" {
value = module.azurerm_virtual_network.data.vnet_hub.id
}

output "vnet_subnet_id" {
value = module.azurerm_virtual_network.data.vnet_subnet.id
}

output "public_ip_prefix_ids" {
value = {
egress_id = module.azurerm_public_ip_prefix_egress.data.id
ingress_id = module.azurerm_public_ip_prefix_ingress.data.id
}
}
22 changes: 0 additions & 22 deletions terraform/subscriptions/s940/c2/key-vault/.terraform.lock.hcl

This file was deleted.

24 changes: 0 additions & 24 deletions terraform/subscriptions/s940/c2/key-vault/backend.tf

This file was deleted.

25 changes: 0 additions & 25 deletions terraform/subscriptions/s940/c2/key-vault/main.tf

This file was deleted.

16 changes: 0 additions & 16 deletions terraform/subscriptions/s940/c2/key-vault/variables.tf

This file was deleted.

19 changes: 19 additions & 0 deletions terraform/subscriptions/s940/extmon/common/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 382d9d7

Please sign in to comment.