From a65e6e1046d577365e4cc902d4d67053cc9a0df1 Mon Sep 17 00:00:00 2001 From: Gillian Stravers Date: Thu, 21 Nov 2024 13:35:55 +0100 Subject: [PATCH] commit --- .terraform.lock.hcl | 22 ++++++++++++++++++++++ main.tf | 11 ++++++----- variables.tf | 20 ++++++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 .terraform.lock.hcl diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..9700cb6 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/azurerm" { + version = "4.10.0" + constraints = ">= 4.0.0" + hashes = [ + "h1:GE4x5zs03lqkgPgzBs86PXhRRJUyqF7dwc7hDVNlSqI=", + "zh:0fe9fc17b0146f29eaefd2bbce7daad93e011de4ba2dca5a6422bea521120737", + "zh:3a1ff1792c3341a9666522b36a45910cf83a35d7c632e45d5a0e0e25a4323284", + "zh:491886b0fc298f7b15a4f3f56a5ff521b3782a8675c0b8512bb92d02c41ff562", + "zh:629cb97dc98e05f167fd9b4ec4e491f484e38291eaf8c69d887f0a136ee45e31", + "zh:80993263737317400981f5bf2b3c2634962e086f4fdd6f995c295202afcea383", + "zh:a490d8f0c6005e20c7024a99073ef5c9f98427d2a7ddfdab47bc39b9060b0b2e", + "zh:a736d534a057f5dbc39272b1952981ba2507c3681e3f9f431c3951c98444b9e2", + "zh:a8831d3d9fbc9972956b639501c180711271928f05aa4ae409045e39fbd41469", + "zh:c0cd073a5ca178fc3ea866d59b437c20158c2fcd57d24431eec575d505da77eb", + "zh:caa667363a0b5ed4df5fc21544ea0123709d77cdd158870fc452a3ee328cf4ab", + "zh:cc15f1f28c9230b66825e893b47264279bb6a1c9dd49c588a896d7666ebea5ed", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/main.tf b/main.tf index 14109ca..651128c 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,5 @@ resource "azurerm_resource_group" "this" { + count = var.create_resource_group ? 1 : 0 name = var.resource_group.name location = var.resource_group.location tags = merge( @@ -10,12 +11,12 @@ resource "azurerm_resource_group" "this" { } resource "azurerm_ip_group" "this" { - for_each = var.ipgroups - name = var.ipgroups.name - location = var.resource_group.location - resource_group_name = azurerm_resource_group.this.name + for_each = var.ipgroups - cidrs = var.ipgroups.cidrs + name = each.value.name + location = var.resource_group.location + resource_group_name = var.resource_group.name + cidrs = each.value.cidrs tags = merge( try(var.tags), diff --git a/variables.tf b/variables.tf index 9257e10..11a3710 100644 --- a/variables.tf +++ b/variables.tf @@ -1,16 +1,28 @@ +variable "create_resource_group" { + description = "A flag to create the Resource Group" + type = bool + default = true +} + variable "resource_group" { description = "The Resource Group to create" - type = object({ + type = object({ name = string location = string }) } +variable "tags" { + description = "A map of tags to assign to the resource." + type = map(string) + default = {} +} + variable "ipgroups" { description = "A map of IP Groups to create" - type = map(object({ + type = map(object({ name = string cidrs = list(string) - }) + }) ) -} \ No newline at end of file +}