From 74c99b7a45a007e749891a5fdce080b22bcd7940 Mon Sep 17 00:00:00 2001 From: wai-wong-edb <119956756+wai-wong-edb@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:52:40 +0100 Subject: [PATCH] fix: v1.1.0 misc fixes (#592) * fix: support service name in cluster resources * fix: data source tag description * fix: duplicate tags not allowed * fix: examples improved --- .../aws/resource.tf | 4 ++-- .../resources/biganimal_cluster/ha/resource.tf | 4 ++-- .../single_node/aws/resource.tf | 4 ++-- .../single_node/azure/resource.tf | 4 ++-- .../single_node/gcp/resource.tf | 4 ++-- .../biganimal_faraway_replica/aws/resource.tf | 4 ++-- .../azure/resource.tf | 4 ++-- .../cluster_and_faraway_replica/resource.tf | 4 ++-- .../biganimal_faraway_replica/gcp/resource.tf | 4 ++-- .../biganimal_pgd/aws/data_group/resource.tf | 4 ++-- .../data_groups_with_witness_group/resource.tf | 4 ++-- .../biganimal_pgd/azure/data_group/resource.tf | 4 ++-- .../data_groups_with_witness_group/resource.tf | 4 ++-- .../biganimal_pgd/gcp/data_group/resource.tf | 4 ++-- .../data_groups_with_witness_group/resource.tf | 4 ++-- .../resources/biganimal_project/resource.tf | 4 ++-- .../resources/biganimal_region/resource.tf | 18 +++++++++--------- pkg/plan_modifier/assign_tags.go | 15 ++++++++++++++- 18 files changed, 55 insertions(+), 42 deletions(-) diff --git a/examples/resources/biganimal_analytics_cluster/aws/resource.tf b/examples/resources/biganimal_analytics_cluster/aws/resource.tf index 3fc59d8e..f8021f3d 100644 --- a/examples/resources/biganimal_analytics_cluster/aws/resource.tf +++ b/examples/resources/biganimal_analytics_cluster/aws/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_analytics_cluster" "analytics_cluster" { #tags = [ # { - # tag_name = "ex-tag-name" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name" + # tag_name = "" # }, #] diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index e3e34df1..c11a2f9c 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -103,11 +103,11 @@ resource "biganimal_cluster" "ha_cluster" { #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index b9d088b9..3b4a7a09 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -104,11 +104,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index 848dc877..8e808bfd 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -105,11 +105,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index 3c16fd2b..e4ace2d6 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -105,11 +105,11 @@ resource "biganimal_cluster" "single_node_cluster" { #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] diff --git a/examples/resources/biganimal_faraway_replica/aws/resource.tf b/examples/resources/biganimal_faraway_replica/aws/resource.tf index 860d8f23..23fa4bf0 100644 --- a/examples/resources/biganimal_faraway_replica/aws/resource.tf +++ b/examples/resources/biganimal_faraway_replica/aws/resource.tf @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "ap-south-1" #tags { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" #} #tags { - # tag_name = "ex-tag-name-2" + # tag_name = "" #} # pe_allowed_principal_ids = [ diff --git a/examples/resources/biganimal_faraway_replica/azure/resource.tf b/examples/resources/biganimal_faraway_replica/azure/resource.tf index 6215cb2e..266f1555 100644 --- a/examples/resources/biganimal_faraway_replica/azure/resource.tf +++ b/examples/resources/biganimal_faraway_replica/azure/resource.tf @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "australiaeast" #tags { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" #} #tags { - # tag_name = "ex-tag-name-2" + # tag_name = "" #} # pe_allowed_principal_ids = [ diff --git a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf index daaa82be..16b6b3e0 100644 --- a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf @@ -106,11 +106,11 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "centralindia" #tags { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" #} #tags { - # tag_name = "ex-tag-name-2" + # tag_name = "" #} # transparent_data_encryption = { diff --git a/examples/resources/biganimal_faraway_replica/gcp/resource.tf b/examples/resources/biganimal_faraway_replica/gcp/resource.tf index 339816e9..825a7e85 100644 --- a/examples/resources/biganimal_faraway_replica/gcp/resource.tf +++ b/examples/resources/biganimal_faraway_replica/gcp/resource.tf @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" { region = "us-east1" #tags { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" #} #tags { - # tag_name = "ex-tag-name-2" + # tag_name = "" #} # pe_allowed_principal_ids = [ diff --git a/examples/resources/biganimal_pgd/aws/data_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_group/resource.tf index 4acae4a3..f8834075 100644 --- a/examples/resources/biganimal_pgd/aws/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf index 31a53839..20df343e 100644 --- a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/data_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_group/resource.tf index 1b42f1bc..939079ec 100644 --- a/examples/resources/biganimal_pgd/azure/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf index b0add02f..ccd0c0ab 100644 --- a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf index 58ea5208..3d87ea68 100644 --- a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf index 23c597b4..9631ad78 100644 --- a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" { pause = false #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] data_groups = [ diff --git a/examples/resources/biganimal_project/resource.tf b/examples/resources/biganimal_project/resource.tf index 5e524ea1..9d5c523e 100644 --- a/examples/resources/biganimal_project/resource.tf +++ b/examples/resources/biganimal_project/resource.tf @@ -19,11 +19,11 @@ resource "biganimal_project" "this" { project_name = format("TF %s", title(random_pet.project_name.id)) #tags = [ # { - # tag_name = "ex-tag-name-1" + # tag_name = "" # color = "blue" # }, # { - # tag_name = "ex-tag-name-2" + # tag_name = "" # }, #] } diff --git a/examples/resources/biganimal_region/resource.tf b/examples/resources/biganimal_region/resource.tf index 8d7a51fe..916ee7bf 100644 --- a/examples/resources/biganimal_region/resource.tf +++ b/examples/resources/biganimal_region/resource.tf @@ -17,15 +17,15 @@ resource "biganimal_region" "this" { region_id = "eu-west-1" project_id = var.project_id - tags = [ - { - tag_name = "test" - color = "blue" - }, - { - tag_name = "" - }, - ] + # tags = [ + # { + # tag_name = "" + # color = "blue" + # }, + # { + # tag_name = "" + # }, + # ] } output "region_status" { diff --git a/pkg/plan_modifier/assign_tags.go b/pkg/plan_modifier/assign_tags.go index 9a300add..ead1d826 100644 --- a/pkg/plan_modifier/assign_tags.go +++ b/pkg/plan_modifier/assign_tags.go @@ -26,9 +26,11 @@ func (m assignTagsModifier) MarkdownDescription(_ context.Context) string { } // PlanModifySet implements the plan modification logic. +// this modifier can merge state with config and return as plan(e.g. state is tags set in UI and config is tags set in terraform config) func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) { state := req.StateValue plan := resp.PlanValue + config := req.ConfigValue // This is on creation. // Do nothing if there is no state value. @@ -44,9 +46,20 @@ func (m assignTagsModifier) PlanModifySet(ctx context.Context, req planmodifier. return } + // check for tag duplicates in config + checkDupes := make(map[string]interface{}) + for _, configTag := range config.Elements() { + tagName := configTag.(basetypes.ObjectValue).Attributes()["tag_name"].(basetypes.StringValue).ValueString() + checkDupes[tagName] = nil + } + + // if checkDupes is not equal to plan.Elements() then there are duplicates + if len(checkDupes) != len(config.Elements()) { + resp.Diagnostics.AddError("Duplicate tag_name not allowed", "Please remove duplicate tag_name") + } + // merge plan into newPlan (plan is from config) and merge state in newPlan (state is from read) newPlan := state.Elements() - for _, planTag := range plan.Elements() { existing := false for _, newPlanElem := range newPlan {