Skip to content

Commit 456f1da

Browse files
authored
Merge pull request #1 from telekom-mms/refactoring
Refactoring Module
2 parents 2e8c084 + c9fa7d9 commit 456f1da

File tree

10 files changed

+53
-68
lines changed

10 files changed

+53
-68
lines changed

.github/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"repos": {
3-
"description": "A Terraform module that manages the tpl_resources resources from the azurerm provider.",
3+
"description": "A Terraform module that manages the authorization resources from the azurerm provider.",
44
"visibility": "public",
55
"default_branch": "main",
66
"topics": [
77
"terraform",
8-
"azure"
8+
"azure",
9+
"role-assignment"
910
]
1011
}
1112
}

examples/apply_main.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
module "tpl_module" {
2-
source = "tpl_source"
3-
tpl_local_name = {
4-
tpl_name = {
5-
location = "westeurope"
6-
resource_group_name = "rg-mms-github"
7-
}
8-
}
9-
}

examples/full_main.tf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +0,0 @@
1-
module "tpl_module" {
2-
source = "tpl_source"
3-
tpl_local_name = {
4-
tpl_name = {
5-
location = "westeurope"
6-
resource_group_name = "rg-mms-github"
7-
tags = {
8-
project = "mms-github"
9-
environment = terraform.workspace
10-
managed-by = "terraform"
11-
}
12-
}
13-
}
14-
}

examples/min_main.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
module "tpl_module" {
2-
source = "tpl_source"
3-
tpl_local_name = {
4-
tpl_name = {
5-
location = "westeurope"
6-
resource_group_name = "rg-mms-github"
7-
}
8-
}
9-
}

main.tf

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
/**
2-
* # tpl_module
2+
* # authorization
33
*
4-
* This module manages the tpl_provider tpl_module resources.
5-
* For more information see https://registry.terraform.io/providers/tpl_provider/latest/docs > tpl_module
4+
* This module manages the azurerm authorization resources.
5+
* For more information see https://registry.terraform.io/providers/azurerm/latest/docs > authorization
66
*
77
*/
88

9-
resource "tpl_resource_type" "tpl_local_name" {
10-
for_each = var.tpl_local_name
9+
resource "azurerm_role_assignment" "role_assignment" {
10+
for_each = var.role_assignment
1111

12-
name = local.tpl_local_name[each.key].name == "" ? each.key : local.tpl_local_name[each.key].name
13-
14-
tags = local.tpl_local_name[each.key].tags
12+
name = local.role_assignment[each.key].name
13+
scope = local.role_assignment[each.key].scope
14+
role_definition_id = local.role_assignment[each.key].role_definition_id
15+
role_definition_name = local.role_assignment[each.key].role_definition_name
16+
principal_id = local.role_assignment[each.key].principal_id
17+
condition = local.role_assignment[each.key].condition
18+
condition_version = local.role_assignment[each.key].condition_version
19+
delegated_managed_identity_resource_id = local.role_assignment[each.key].delegated_managed_identity_resource_id
20+
description = local.role_assignment[each.key].description
21+
skip_service_principal_aad_check = local.role_assignment[each.key].skip_service_principal_aad_check
1522
}

outputs.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
output "tpl_local_name" {
1+
output "role_assignments" {
22
description = "Outputs all attributes of resource_type."
33
value = {
4-
for tpl_local_name in keys(tpl_resource_type.tpl_local_name) :
5-
tpl_local_name => {
6-
for key, value in tpl_resource_type.tpl_local_name[tpl_local_name] :
4+
for role_assignment in keys(azurerm_role_assignment.role_assignment) :
5+
role_assignment => {
6+
for key, value in azurerm_role_assignment.role_assignment[role_assignment] :
77
key => value
88
}
99
}
@@ -17,9 +17,9 @@ output "variables" {
1717
variable => local.default[variable]
1818
}
1919
merged = {
20-
tpl_local_name = {
21-
for key in keys(var.tpl_local_name) :
22-
key => local.tpl_local_name[key]
20+
role_assignment = {
21+
for key in keys(var.role_assignment) :
22+
key => local.role_assignment[key]
2323
}
2424
}
2525
}

providers.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "azurerm" {
2+
features {}
3+
}

tests/terratest.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
# see https://pkg.go.dev/github.com/gruntwork-io/terratest/modules/[package]
21
functions: []
32
options: {}

variables.tf

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
variable "tpl_local_name" {
1+
variable "role_assignment" {
22
type = any
33
default = {}
44
description = "Resource definition, default settings are defined within locals and merged with var settings. For more information look at [Outputs](#Outputs)."
55
}
66

77
locals {
88
default = {
9-
tpl_local_name = {
10-
name = ""
11-
tags = {}
9+
// resource definition
10+
role_assignment = {
11+
name = null
12+
role_definition_id = null
13+
role_definition_name = null
14+
condition = null
15+
condition_version = null
16+
delegated_managed_identity_resource_id = null
17+
description = null
18+
skip_service_principal_aad_check = null
1219
}
1320
}
1421

15-
/**
16-
compare and merge custom and default values
17-
*/
18-
tpl_local_name_values = {
19-
for tpl_local_name in keys(var.tpl_local_name) :
20-
tpl_local_name => merge(local.default.tpl_local_name, var.tpl_local_name[tpl_local_name])
22+
// compare and merge custom and default values
23+
role_assignment_values = {
24+
for role_assignment in keys(var.role_assignment) :
25+
role_assignment => merge(local.default.role_assignment, var.role_assignment[role_assignment])
2126
}
2227

23-
/**
24-
deep merge of all custom and default values
25-
*/
26-
tpl_local_name = {
27-
for tpl_local_name in keys(var.tpl_local_name) :
28-
tpl_local_name => merge(
29-
local.tpl_local_name_values[tpl_local_name],
28+
// deep merge of all custom and default values
29+
role_assignment = {
30+
for role_assignment in keys(var.role_assignment) :
31+
role_assignment => merge(
32+
local.role_assignment_values[role_assignment],
3033
{}
3134
)
3235
}

versions.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
terraform {
22
required_providers {
3+
azurerm = {
4+
source = "registry.terraform.io/hashicorp/azurerm"
5+
version = ">=3.59.0"
6+
}
37
}
4-
required_version = ">=1.3"
8+
required_version = ">=1.4"
59
}

0 commit comments

Comments
 (0)