Skip to content

Commit

Permalink
fix: v1.1.0 misc fixes (#592)
Browse files Browse the repository at this point in the history
* fix: support service name in cluster resources

* fix: data source tag description

* fix: duplicate tags not allowed

* fix: examples improved
  • Loading branch information
wai-wong-edb authored Oct 9, 2024
1 parent 0ab00c2 commit 74c99b7
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_analytics_cluster" "analytics_cluster" {

#tags = [
# {
# tag_name = "ex-tag-name"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name"
# tag_name = "<ex_tag_name_2>"
# },
#]

Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_cluster/ha/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ resource "biganimal_cluster" "ha_cluster" {

#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ resource "biganimal_cluster" "single_node_cluster" {

#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ resource "biganimal_cluster" "single_node_cluster" {

#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ resource "biganimal_cluster" "single_node_cluster" {

#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]

Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_faraway_replica/aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
region = "ap-south-1"

#tags {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
#}
#tags {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
#}

# pe_allowed_principal_ids = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
region = "australiaeast"

#tags {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
#}
#tags {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
#}

# pe_allowed_principal_ids = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
region = "centralindia"

#tags {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
#}
#tags {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
#}

# transparent_data_encryption = {
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_faraway_replica/gcp/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
region = "us-east1"

#tags {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
#}
#tags {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
#}

# pe_allowed_principal_ids = [
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_pgd/aws/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_pgd/azure/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_pgd/gcp/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ resource "biganimal_pgd" "pgd_cluster" {
pause = false
#tags = [
# {
# tag_name = "ex-tag-name-1"
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
data_groups = [
Expand Down
4 changes: 2 additions & 2 deletions examples/resources/biganimal_project/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "ex-tag-name-2"
# tag_name = "<ex_tag_name_2>"
# },
#]
}
Expand Down
18 changes: 9 additions & 9 deletions examples/resources/biganimal_region/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<ex-tag-name-2>"
},
]
# tags = [
# {
# tag_name = "<ex_tag_name_1>"
# color = "blue"
# },
# {
# tag_name = "<ex_tag_name_2>"
# },
# ]
}

output "region_status" {
Expand Down
15 changes: 14 additions & 1 deletion pkg/plan_modifier/assign_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit 74c99b7

Please sign in to comment.