feat(tofu): adding information outputs

adding enable disable support for deployment
This commit is contained in:
Philippe Caseiro 2024-01-17 16:09:34 +01:00
parent 05ecc74731
commit b8e64c4869
5 changed files with 117 additions and 4 deletions

View File

@ -1,7 +1,19 @@
locals {
deployments = {
"ssh" = {
name = "Associer une clef SSH - (2024-01-17)"
description = "Adding user ssh key to project deployments"
enabled = true
catalog_item_name = "Associer une clef SSH"
project_name = "GRP-CLOE-TSS-DEV"
inputs = {
username = var.vra_username
sshpubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDDph3zh6ojSvH44k13z9B6xj+Hargo3uzkxnYv5s5NI4yagNuBXEc3aS++KdocND+FtVfLK+iVE8qHo2bvmpMmVkqU6WU2apN7DfIP0QGLlSGeo+UOZ9hGeEDlgVO4AOnZKZ5kPGBEPZ84JXuE9CmhKfwEVCK8w3B8XQttA8alFl4A4/4F14x2w4njsSLY1H3b0qah7hgYKU5zHIGLg8Lxx+1BxGIF0l5n5m5rqAskRNaF+aYbs0CcWHv49bPK0sJJ0qPV2r2sq8BlzuZFHExnZRIxpsIXdce4Bm4rdlGi7tBmmurLk4OOtDkwvhD0LMaNJf10k6QLSmRUTVzgsYz/dmGxopbMtwwIXkwi014uSZgi8wAuznXx5I4j2TUGPZHOVf+1iw/yaxWlgTVOSoX7ZxyhDgW5cCgZZGNzU5UWe0vUuVTB+hfSMj50/Q6+Vi92/mDMbPhm4nBoVzD5DT15mB+yGyN45Ej61m0JzVUyZexfvVaffEug1/u5dnwilP0WGKr4i2OXxOXtvSdAs5rlZjvppZk6IxRCwXIcPwEFL97ZrQZAxlVS5Nh+ZnlSwTe3zfQhzHj1ao0AdCAHFPUEdoUPJhSb0OjyCvZ9XZ1KCkXhuhuN/3IUhuoWl4soNCeC3KmU/USx1wda438Exj0hM1mTyBZScDPGyD9nw78DGw== Philippe Caseiro"
}
},
"test-pc-vf" = {
name = "test-pc-vf"
enabled = false
description = "test deployment"
catalog_item_name = "MonoVM-Dev"
project_name = "GRP-CLOE-TSS-DEV"
@ -27,8 +39,65 @@ locals {
leaseDays = "1"
}
},
"MonoTest-pc-vf-1" = {
name = "MonoTest-1"
enabled = true
description = "test deployment"
catalog_item_name = "MonoVM-Dev"
project_name = "GRP-CLOE-TSS-DEV"
inputs = {
MonoVM_cpu = 2
MonoVM_memory = 2048
MonoVM_securityTag = "DEV-TIER-WEB"
MonoVM_service = "app"
MonoVM_disks = jsonencode([
{
mountpoint = "/toto",
size = 10
},
{
mountpoint = "/titi",
size = 20
}
])
MonoVM_image = "DEB10X"
MonoVM_instances = 1
MonoVM_startOrder = "1"
leaseDays = "1"
}
},
"MonoTest-pc-vf-2" = {
name = "MonotTest-2"
enabled = true
description = "test deployment"
catalog_item_name = "MonoVM-Dev"
project_name = "GRP-CLOE-TSS-DEV"
inputs = {
MonoVM_cpu = 2
MonoVM_memory = 2048
MonoVM_securityTag = "DEV-TIER-APP"
MonoVM_service = "app"
MonoVM_disks = jsonencode([
{
mountpoint = "/toto",
size = 10
},
{
mountpoint = "/titi",
size = 200
}
])
MonoVM_image = "DEB10X"
MonoVM_instances = 1
MonoVM_startOrder = "1"
leaseDays = "1"
}
},
"test-pc-vf-3-tiers" = {
name = "test-pc-vf-3-tiers"
enabled = true
description = "test 3 tiers Dev"
catalog_item_name = "3-tiers-Dev"
project_name = "GRP-CLOE-TST-DEV"

View File

@ -5,6 +5,13 @@ variable "vra_refresh_token" {
type = string
sensitive = true
}
variable "vra_username" {
type = string
}
data "local_file" "ssh-pub-key" {
filename = "/home/pcaseiro/.ssh/id_rsa.pub"
}
module "deployment" {
source = "./modules/pycloud"
@ -14,4 +21,34 @@ module "deployment" {
vra_insecure_ssl = true
deployments = local.deployments
}
/*
output "flatten_vms" {
value = flatten([
for k1, deploy in module.deployment.deployments : [
for k2, resource in deploy.resources : {
deployment_name = k1
vm_name = jsondecode(resource.properties_json).name
vm_hostname = jsondecode(resource.properties_json).hostName
address = jsondecode(resource.properties_json).address
networks = jsondecode(resource.properties_json).networks
} if resource.type == "Cloud.vSphere.Machine"
]
])
}
*/
output "vms" {
value = flatten([
for k1, deploy in module.deployment.deployments : {
for k2, resource in deploy.resources : jsondecode(resource.properties_json).name => {
deployment_name = k1
vm_name = jsondecode(resource.properties_json).name
vm_hostname = jsondecode(resource.properties_json).hostName
address = jsondecode(resource.properties_json).address
networks = jsondecode(resource.properties_json).networks
} if resource.type == "Cloud.vSphere.Machine"
}
])
}

View File

@ -1,10 +1,10 @@
data "vra_project" "projects" {
for_each = { for deployment in var.deployments : deployment.project_name => deployment }
for_each = { for deployment in var.deployments : deployment.project_name => deployment... }
name = each.key
}
data "vra_catalog_item" "catalog" {
for_each = { for deployment in var.deployments : deployment.catalog_item_name => deployment }
for_each = { for deployment in var.deployments : deployment.catalog_item_name => deployment... }
name = each.key
expand_versions = true
@ -12,7 +12,11 @@ data "vra_catalog_item" "catalog" {
}
resource "vra_deployment" "deployments" {
for_each = var.deployments
//for_each = { for deployment in var.deployments: deployment => deployment if deployment.enabled }
for_each = {
for name, deployment in var.deployments : name => deployment
if deployment.enabled
}
name = each.value.name
description = each.value.description

View File

@ -39,6 +39,7 @@ variable "deployments" {
type = map(object({
name = string
description = string
enabled = bool
catalog_item_name = string
project_name = string

View File

@ -64,6 +64,7 @@ else
if [ ! -f "${TOKENRC}" ]; then
echo "service_url=${service_url}" >> "${TOKENRC}"
echo "refresh_token=${refresh_token}" >> "${TOKENRC}"
echo "username=${username}" >> "${TOKENRC}"
chmod 600 ${TOKENRC}
fi
fi
@ -77,5 +78,6 @@ fi
ARG1=${@:$OPTIND:1}
export TF_VAR_vra_url="${service_url}"
export TF_VAR_vra_username="${username}"
export TF_VAR_vra_refresh_token="${refresh_token}"
tofu ${ARG1}
tofu ${ARG1} -no-color