Skip to content

Commit

Permalink
Added Vnets and Private DNS Zones (#1157)
Browse files Browse the repository at this point in the history
Co-authored-by: Automatic Update <[email protected]>
  • Loading branch information
sveinpj and Automatic Update authored Jan 24, 2024
1 parent e503360 commit 2908b50
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 34 deletions.
1 change: 1 addition & 0 deletions terraform/subscriptions/s940/c2/common/common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ locals {
outputs = {
location = "westeurope"
resource_group = "common-westeurope"
enviroment = "c2"
}
}
2 changes: 1 addition & 1 deletion terraform/subscriptions/s940/c2/common/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}"
name = each.value
location = local.outputs.location
}
12 changes: 10 additions & 2 deletions terraform/subscriptions/s940/c2/virtualnetwork/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}-${local.external_outputs.common.data.enviroment}"
location = local.external_outputs.common.data.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = local.external_outputs.clusters.data.location
enviroment = local.external_outputs.clusters.data.enviroment
location = local.external_outputs.common.data.location
enviroment = local.external_outputs.common.data.enviroment
depends_on = [module.resourcegroups]
}

4 changes: 4 additions & 0 deletions terraform/subscriptions/s940/c2/virtualnetwork/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_groups" {
type = list(string)
default = ["cluster-vnet-hub"]
}
1 change: 1 addition & 0 deletions terraform/subscriptions/s940/prod/common/common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ locals {
outputs = {
location = "northeurope"
resource_group = "common"
enviroment = "platform"
}
}
2 changes: 1 addition & 1 deletion terraform/subscriptions/s940/prod/common/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}"
name = each.value
location = local.outputs.location
}
12 changes: 10 additions & 2 deletions terraform/subscriptions/s940/prod/virtualnetwork/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}-${local.external_outputs.common.data.enviroment}"
location = local.external_outputs.common.data.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = local.external_outputs.clusters.data.location
enviroment = local.external_outputs.clusters.data.enviroment
location = local.external_outputs.common.data.location
enviroment = local.external_outputs.common.data.enviroment
depends_on = [module.resourcegroups]
}
4 changes: 4 additions & 0 deletions terraform/subscriptions/s940/prod/virtualnetwork/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_groups" {
type = list(string)
default = ["cluster-vnet-hub"]
}
38 changes: 29 additions & 9 deletions terraform/subscriptions/s940/summary-c2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,32 @@ normal=$(tput sgr0)

# Set the directory you want to search
directory="./c2"
find "$directory" -mindepth 1 -maxdepth 1 -type d -exec bash -c '
for dir; do
printf "%s► Execute %s%s\n" "${grn}" "$dir" "${normal}"
#echo "$dir"
terraform -chdir=$dir plan -no-color
# Perform actions here for each directory
# For example, you can add commands to operate on each directory
done
' bash {} +

for dir in "$directory"/*; do
if [ ! -d "$dir" ]; then continue; fi

printf "%s► Execute %s%s\n" "${grn}" "$dir" "${normal}"
terraform -chdir="$dir" init &>/dev/null || echo "Error during terraform init in $dir"
terraform -chdir="$dir" plan -no-color -out=plan.out &>/dev/null || echo "Error during terraform plan in $dir"

if [ ! -f "$dir/plan.out" ]; then
echo "plan.out was not created in $dir"
continue
fi

cd "$dir" || exit
plan=$(terraform show -no-color "plan.out")
cd - >/dev/null || exit

create=$(echo "$plan" | grep "will be created" | sed 's|# |+|g' | sed 's/^ *//g')
destroy=$(echo "$plan" | grep "will be destroyed" | sed 's|# |-|g' | sed 's/^ *//g')
update=$(echo "$plan" | grep "will be updated in-place" | sed 's|# |~|g' | sed 's/^ *//g')
replace=$(echo "$plan" | grep "must be replaced" | sed 's|# |-/+|g' | sed 's/^ *//g')

if [ -n "$create" ]; then echo -e "The following resources will be created:\n ${grn}${create}${normal}\n"; fi
if [ -n "$destroy" ]; then echo -e "The following resources will be destroyed:\n ${red}${destroy}${normal}\n"; fi
if [ -n "$update" ]; then echo -e "The following resources will be updated:\n ${yel}${update}${normal}\n"; fi
if [ -n "$replace" ]; then echo -e "The following resources will be replaced:\n ${red}${replace}${normal}\n"; fi
if [ -z "$create$destroy$update$replace" ]; then echo -e "No changes. Your infrastructure matches the configuration.\n"; fi
rm "$dir/plan.out"
done
38 changes: 29 additions & 9 deletions terraform/subscriptions/s940/summary-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,32 @@ normal=$(tput sgr0)

# Set the directory you want to search
directory="./prod"
find "$directory" -mindepth 1 -maxdepth 1 -type d -exec bash -c '
for dir; do
printf "%s► Execute %s%s\n" "${grn}" "$dir" "${normal}"
#echo "$dir"
terraform -chdir=$dir plan -no-color
# Perform actions here for each directory
# For example, you can add commands to operate on each directory
done
' bash {} +

for dir in "$directory"/*; do
if [ ! -d "$dir" ]; then continue; fi

printf "%s► Execute %s%s\n" "${grn}" "$dir" "${normal}"
terraform -chdir="$dir" init &>/dev/null || echo "Error during terraform init in $dir"
terraform -chdir="$dir" plan -no-color -out=plan.out &>/dev/null || echo "Error during terraform plan in $dir"

if [ ! -f "$dir/plan.out" ]; then
echo "plan.out was not created in $dir"
continue
fi

cd "$dir" || exit
plan=$(terraform show -no-color "plan.out")
cd - >/dev/null || exit

create=$(echo "$plan" | grep "will be created" | sed 's|# |+|g' | sed 's/^ *//g')
destroy=$(echo "$plan" | grep "will be destroyed" | sed 's|# |-|g' | sed 's/^ *//g')
update=$(echo "$plan" | grep "will be updated in-place" | sed 's|# |~|g' | sed 's/^ *//g')
replace=$(echo "$plan" | grep "must be replaced" | sed 's|# |-/+|g' | sed 's/^ *//g')

if [ -n "$create" ]; then echo -e "The following resources will be created:\n ${grn}${create}${normal}\n"; fi
if [ -n "$destroy" ]; then echo -e "The following resources will be destroyed:\n ${red}${destroy}${normal}\n"; fi
if [ -n "$update" ]; then echo -e "The following resources will be updated:\n ${yel}${update}${normal}\n"; fi
if [ -n "$replace" ]; then echo -e "The following resources will be replaced:\n ${red}${replace}${normal}\n"; fi
if [ -z "$create$destroy$update$replace" ]; then echo -e "No changes. Your infrastructure matches the configuration.\n"; fi
rm "$dir/plan.out"
done
2 changes: 1 addition & 1 deletion terraform/subscriptions/s941/dev/common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}"
name = each.value
location = local.outputs.location
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/subscriptions/s941/dev/common/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variable "storageaccounts" {
description = "Max 15 characters lowercase in the storageaccount name"
type = map(object({
name = string
resource_group_name = optional(string, "s941-development")
resource_group_name = optional(string, "common-development")
location = optional(string, "northeurope")
account_tier = optional(string, "Standard")
account_replication_type = optional(string, "LRS")
Expand Down
11 changes: 9 additions & 2 deletions terraform/subscriptions/s941/dev/virtualnetwork/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}-${local.external_outputs.common.data.enviroment}"
location = local.external_outputs.common.data.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = local.external_outputs.common.data.location
enviroment = local.external_outputs.common.data.enviroment_S
}
enviroment = local.external_outputs.common.data.enviroment
}
4 changes: 4 additions & 0 deletions terraform/subscriptions/s941/dev/virtualnetwork/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_groups" {
type = list(string)
default = ["cluster-vnet-hub"]
}
1 change: 1 addition & 0 deletions terraform/subscriptions/s941/playground/common/common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ locals {
outputs = {
location = "northeurope"
resource_group = "common"
enviroment = "playground"
enviroment_L = "playground"
enviroment_S = "playground"
}
Expand Down
36 changes: 34 additions & 2 deletions terraform/subscriptions/s941/playground/common/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}"
name = each.value
location = local.outputs.location
}
}

module "backupvault" {
source = "../../../modules/backupvaults"
name = "Backupvault-${local.outputs.enviroment}"
resource_group_name = "common-${local.outputs.enviroment}"
location = local.outputs.location
policyblobstoragename = "Backuppolicy-blob"
depends_on = [module.resourcegroups]
}

# module "storageaccount" {
# source = "../../../modules/storageaccount"
# for_each = var.storageaccounts
# name = "${each.key}${local.outputs.enviroment}"
# tier = each.value.account_tier
# account_replication_type = each.value.account_replication_type
# resource_group_name = each.value.resource_group_name
# location = each.value.location
# environment = local.outputs.enviroment
# kind = each.value.kind
# change_feed_enabled = each.value.change_feed_enabled
# versioning_enabled = each.value.versioning_enabled
# roleassignment = each.value.roleassignment
# principal_id = module.backupvault.data.backupvault.identity[0].principal_id
# vault_id = module.backupvault.data.backupvault.id
# policyblobstorage_id = module.backupvault.data.policyblobstorage.id
# subnet_id = local.external_outputs.virtualnetwork.data.vnet_subnet.id
# vnethub_resource_group = local.external_outputs.virtualnetwork.data.vnet_hub.resource_group_name
# priv_endpoint = each.value.private_endpoint
# firewall = each.value.firewall
# depends_on = [ module.backupvault ]
# }
23 changes: 23 additions & 0 deletions terraform/subscriptions/s941/playground/common/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
variable "resource_groups" {
type = list(string)
default = ["common-playground"]
}

variable "storageaccounts" {
description = "Max 15 characters lowercase in the storageaccount name"
type = map(object({
name = string
resource_group_name = optional(string, "common-playground")
location = optional(string, "northeurope")
account_tier = optional(string, "Standard")
account_replication_type = optional(string, "LRS")
kind = optional(string, "StorageV2")
change_feed_enabled = optional(bool, false)
versioning_enabled = optional(bool, false)
roleassignment = optional(map(object({ backup = optional(bool, false) })))
principal_id = optional(string)
private_endpoint = optional(bool, false)
firewall = optional(bool, true)
}))
default = {
radixlog = {
name = "radixlog"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module "resourcegroups" {
for_each = toset(var.resource_groups)
source = "../../../modules/resourcegroups"
name = "${each.value}-${local.external_outputs.common.data.enviroment}"
location = local.external_outputs.common.data.location
}

module "azurerm_virtual_network" {
source = "../../../modules/virtualnetwork"
location = local.external_outputs.common.data.location
enviroment = local.external_outputs.common.data.enviroment_S
enviroment = local.external_outputs.common.data.enviroment
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "data" {
value = module.azurerm_virtual_network.data
}
# output "data" {
# value = module.azurerm_virtual_network.data
# }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_groups" {
type = list(string)
default = ["cluster-vnet-hub"]
}

0 comments on commit 2908b50

Please sign in to comment.