Skip to content

Commit

Permalink
Merge pull request #1 from telekom-mms/refactoring
Browse files Browse the repository at this point in the history
Refactoring Module
  • Loading branch information
michaelamattes authored Jul 12, 2023
2 parents 2e8c084 + c9fa7d9 commit 456f1da
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .github/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"repos": {
"description": "A Terraform module that manages the tpl_resources resources from the azurerm provider.",
"description": "A Terraform module that manages the authorization resources from the azurerm provider.",
"visibility": "public",
"default_branch": "main",
"topics": [
"terraform",
"azure"
"azure",
"role-assignment"
]
}
}
9 changes: 0 additions & 9 deletions examples/apply_main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
module "tpl_module" {
source = "tpl_source"
tpl_local_name = {
tpl_name = {
location = "westeurope"
resource_group_name = "rg-mms-github"
}
}
}
14 changes: 0 additions & 14 deletions examples/full_main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
module "tpl_module" {
source = "tpl_source"
tpl_local_name = {
tpl_name = {
location = "westeurope"
resource_group_name = "rg-mms-github"
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
}
9 changes: 0 additions & 9 deletions examples/min_main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
module "tpl_module" {
source = "tpl_source"
tpl_local_name = {
tpl_name = {
location = "westeurope"
resource_group_name = "rg-mms-github"
}
}
}
23 changes: 15 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/**
* # tpl_module
* # authorization
*
* This module manages the tpl_provider tpl_module resources.
* For more information see https://registry.terraform.io/providers/tpl_provider/latest/docs > tpl_module
* This module manages the azurerm authorization resources.
* For more information see https://registry.terraform.io/providers/azurerm/latest/docs > authorization
*
*/

resource "tpl_resource_type" "tpl_local_name" {
for_each = var.tpl_local_name
resource "azurerm_role_assignment" "role_assignment" {
for_each = var.role_assignment

name = local.tpl_local_name[each.key].name == "" ? each.key : local.tpl_local_name[each.key].name

tags = local.tpl_local_name[each.key].tags
name = local.role_assignment[each.key].name
scope = local.role_assignment[each.key].scope
role_definition_id = local.role_assignment[each.key].role_definition_id
role_definition_name = local.role_assignment[each.key].role_definition_name
principal_id = local.role_assignment[each.key].principal_id
condition = local.role_assignment[each.key].condition
condition_version = local.role_assignment[each.key].condition_version
delegated_managed_identity_resource_id = local.role_assignment[each.key].delegated_managed_identity_resource_id
description = local.role_assignment[each.key].description
skip_service_principal_aad_check = local.role_assignment[each.key].skip_service_principal_aad_check
}
14 changes: 7 additions & 7 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "tpl_local_name" {
output "role_assignments" {
description = "Outputs all attributes of resource_type."
value = {
for tpl_local_name in keys(tpl_resource_type.tpl_local_name) :
tpl_local_name => {
for key, value in tpl_resource_type.tpl_local_name[tpl_local_name] :
for role_assignment in keys(azurerm_role_assignment.role_assignment) :
role_assignment => {
for key, value in azurerm_role_assignment.role_assignment[role_assignment] :
key => value
}
}
Expand All @@ -17,9 +17,9 @@ output "variables" {
variable => local.default[variable]
}
merged = {
tpl_local_name = {
for key in keys(var.tpl_local_name) :
key => local.tpl_local_name[key]
role_assignment = {
for key in keys(var.role_assignment) :
key => local.role_assignment[key]
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "azurerm" {
features {}
}
1 change: 0 additions & 1 deletion tests/terratest.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# see https://pkg.go.dev/github.com/gruntwork-io/terratest/modules/[package]
functions: []
options: {}
37 changes: 20 additions & 17 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
variable "tpl_local_name" {
variable "role_assignment" {
type = any
default = {}
description = "Resource definition, default settings are defined within locals and merged with var settings. For more information look at [Outputs](#Outputs)."
}

locals {
default = {
tpl_local_name = {
name = ""
tags = {}
// resource definition
role_assignment = {
name = null
role_definition_id = null
role_definition_name = null
condition = null
condition_version = null
delegated_managed_identity_resource_id = null
description = null
skip_service_principal_aad_check = null
}
}

/**
compare and merge custom and default values
*/
tpl_local_name_values = {
for tpl_local_name in keys(var.tpl_local_name) :
tpl_local_name => merge(local.default.tpl_local_name, var.tpl_local_name[tpl_local_name])
// compare and merge custom and default values
role_assignment_values = {
for role_assignment in keys(var.role_assignment) :
role_assignment => merge(local.default.role_assignment, var.role_assignment[role_assignment])
}

/**
deep merge of all custom and default values
*/
tpl_local_name = {
for tpl_local_name in keys(var.tpl_local_name) :
tpl_local_name => merge(
local.tpl_local_name_values[tpl_local_name],
// deep merge of all custom and default values
role_assignment = {
for role_assignment in keys(var.role_assignment) :
role_assignment => merge(
local.role_assignment_values[role_assignment],
{}
)
}
Expand Down
6 changes: 5 additions & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
terraform {
required_providers {
azurerm = {
source = "registry.terraform.io/hashicorp/azurerm"
version = ">=3.59.0"
}
}
required_version = ">=1.3"
required_version = ">=1.4"
}

0 comments on commit 456f1da

Please sign in to comment.