Skip to content

Commit

Permalink
[CES-203] Added new module for retrieve of common values (#1243)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea Grillo <[email protected]>
  • Loading branch information
mamu0 and Krusty93 authored Oct 18, 2024
1 parent ca06c39 commit 4a1a179
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/_modules/common_values/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Retrieve Common Values

## Description

This Terraform module does not require any input and provides some outputs containg common information for whole `io-infra` repository.
To update the module with new information add into the outputs.tf
```hcl
output "some_resource_name" {
description = <<EOF
WHAT: short description about what this value is for
HOW: short description about how this value will be used (optional)
EOF
value = "example_value"
}
```

## Usage

Include the module in your Terraform configuration and access the outputs to retrieve the information.

### Example Usage

```hcl
module "common_names" {
source = "../../_modules/common_values"
}
output "some_resource_name" {
value = module.common_names.some_resource_name
}
```
20 changes: 20 additions & 0 deletions src/_modules/common_values/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
data "azurerm_virtual_network" "weu_beta" {
name = "${local.project_weu}-beta-vnet"
resource_group_name = "${local.project_weu}-beta-vnet-rg"
}

data "azurerm_virtual_network" "weu_prod01" {
name = "${local.project_weu}-prod01-vnet"
resource_group_name = "${local.project_weu}-prod01-vnet-rg"
}

data "terraform_remote_state" "core" {
backend = "azurerm"

config = {
resource_group_name = "terraform-state-rg"
storage_account_name = "iopitntfst001"
container_name = "terraform-state"
key = "io-infra.core.prod.italynorth.tfstate"
}
}
34 changes: 34 additions & 0 deletions src/_modules/common_values/example/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "<= 3.116.0"
}
}
}

provider "azurerm" {
features {}
}


#--
module "common_values" {
source = "../../"
}

output "vnets" {
value = module.common_values.virtual_networks
}

output "pep_snet" {
value = module.common_values.pep_subnets
}

output "resource_groups" {
value = module.common_values.resource_groups
}

output "dns_zones" {
value = module.common_values.dns_zones
}
14 changes: 14 additions & 0 deletions src/_modules/common_values/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
locals {
prefix = "io"
env_short = "p"
location_short = {
westeurope = "weu",
italynorth = "itn",
germanywestcentral = "gwc",
northeurope = "neu"
}
project_itn = "${local.prefix}-${local.env_short}-${local.location_short.italynorth}"
project_weu = "${local.prefix}-${local.env_short}-${local.location_short.westeurope}"
project_weu_legacy = "${local.prefix}-${local.env_short}"
core = data.terraform_remote_state.core.outputs
}
13 changes: 13 additions & 0 deletions src/_modules/common_values/outputs_configurable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

output "scaling_gate" {
description = <<EOF
WHAT: Name and configuration for gates on release, to be changed at each release with the most up-to-date values
HOW: These values ​​will be used for scaling the different resources (function app, app services, etc.)
EOF
value = {
name = "gate1"
timezone = "W. Europe Standard Time"
start = "2024-10-23T08:00:00.000Z"
end = "2024-10-23T22:00:00.000Z"
}
}
23 changes: 23 additions & 0 deletions src/_modules/common_values/outputs_general.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output "resource_groups" {
description = <<EOF
WHAT: All resource groups into itn and weu regions
EOF
value = {
weu = {
common = "${local.project_weu_legacy}-rg-common"
internal = "${local.project_weu_legacy}-rg-internal"
external = "${local.project_weu_legacy}-rg-external"
event = "${local.project_weu_legacy}-evt-rg"
sec = "${local.project_weu_legacy}-sec-rg"
linux = "${local.project_weu_legacy}-rg-linux"
},
itn = {
common = "${local.project_itn}-common-rg-01"
internal = "${local.project_itn}-common-rg-01"
external = "${local.project_itn}-common-rg-01"
event = "${local.project_itn}-common-rg-01"
sec = "${local.project_itn}-sec-rg-01"
linux = "${local.project_itn}-common-rg-01"
}
}
}
64 changes: 64 additions & 0 deletions src/_modules/common_values/outputs_network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

output "virtual_networks" {
description = <<EOF
WHAT: All vnets into itn and weu regions
EOF
value = {
itn = {
common = local.core.networking.itn.vnet_common
}
weu = {
common = local.core.networking.weu.vnet_common
beta = {
name = data.azurerm_virtual_network.weu_beta.name
resource_group_name = data.azurerm_virtual_network.weu_beta.resource_group_name
}
prod01 = {
name = data.azurerm_virtual_network.weu_prod01.name
resource_group_name = data.azurerm_virtual_network.weu_prod01.resource_group_name
}
}
}
}

output "pep_subnets" {
description = <<EOF
WHAT: Private Endpoint dedicated subnets into itn and weu regions
EOF
value = {
itn = {
id = local.core.networking.itn.pep_snet.id
},
weu = {
id = local.core.networking.weu.pep_snet.id
}
}
}

output "dns_zones" {
description = <<EOF
WHAT: All common dns zones
EOF
value = {
io_italia = {
name = "io.italia.it"
resource_group_name = "${local.project_weu_legacy}-rg-external"
}
io_papopa = {
name = "io.pagopa.it"
resource_group_name = "${local.project_weu_legacy}-rg-external"
}
io_selfcare = {
name = "io.selfcare.pagopa.it"
resource_group_name = "${local.project_weu_legacy}-rg-external"
}
firmaconio_selfcare = {
name = "firmaconio.selfcare.pagopa.it"
resource_group_name = "${local.project_weu_legacy}-rg-external"
}
io_web = {
name = "ioapp.it"
resource_group_name = "${local.project_weu_legacy}-rg-external"
}
}
}

0 comments on commit 4a1a179

Please sign in to comment.