From c3b62a163b1eac08e48e7cc3c16dd8edd93efcd3 Mon Sep 17 00:00:00 2001 From: xpk Date: Thu, 23 Nov 2023 17:00:16 +0800 Subject: [PATCH] UPD: added default_tags validation --- modules/compute/security-groups/main.tf | 5 +---- modules/compute/security_group/main.tf | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/compute/security-groups/main.tf b/modules/compute/security-groups/main.tf index 189a435..be6bc55 100644 --- a/modules/compute/security-groups/main.tf +++ b/modules/compute/security-groups/main.tf @@ -3,10 +3,7 @@ resource "aws_security_group" "sg" { name = var.security-groups[count.index].name description = var.security-groups[count.index].description vpc_id = var.vpc-id - tags = merge( - var.tags, - {Name = var.security-groups[count.index].name} - ) + tags = { Name = var.security-groups[count.index].name } } // see https://www.terraform.io/docs/configuration/functions/flatten.html diff --git a/modules/compute/security_group/main.tf b/modules/compute/security_group/main.tf index 136c277..590eb9b 100644 --- a/modules/compute/security_group/main.tf +++ b/modules/compute/security_group/main.tf @@ -1,4 +1,11 @@ -data aws_default_tags this {} +data "aws_default_tags" "this" { + lifecycle { + postcondition { + condition = length(self.tags) >= 1 + error_message = "Validation failed: Provider default_tags not set." + } + } +} resource "aws_security_group" "sg" { name = var.name