Skip to content

Commit

Permalink
add plan modifier to avoid replacement when there is an update
Browse files Browse the repository at this point in the history
  • Loading branch information
dianibar committed Jan 29, 2024
1 parent 91aa879 commit 2c5ec41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ terraform {
}
}
}
resource "doit_attribution" "attri" {
name = "attritestnewname"
description = "attritestdesc"
formula = "A"
components = [{ type = "label", key = "iris_region", values = ["us-central1"] }]
}

resource "doit_attribution_group" "attributeGroup" {
name = "attritestnewgroup"
description = "attritestgroup-new-new"
attributions = [doit_attribution.attri.id]
}

resource "doit_report" "my-report_january" {
name = "my-report"
Expand All @@ -15,7 +27,7 @@ resource "doit_report" "my-report_january" {
type = "basic"
value = "cost"
}
sort_groups = "asc"
sort_groups = "asc"
sort_dimensions = "asc"
advanced_analysis = {
trending_up = true
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/attribution_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -52,6 +54,9 @@ func (r *attributionGroupResource) Schema(ctx context.Context, _ resource.Schema
"id": schema.StringAttribute{
Description: "Numeric identifier of the attribution group",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"last_updated": schema.StringAttribute{
Description: "Timestamp of the last Terraform update of" +
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/attribution_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -59,6 +61,9 @@ func (r *attributionResource) Schema(_ context.Context, _ resource.SchemaRequest
"id": schema.StringAttribute{
Description: "Numeric identifier of the attribution",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"last_updated": schema.StringAttribute{
Description: "Timestamp of the last Terraform update of" +
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/report_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -561,6 +563,9 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res
"id": schema.StringAttribute{
Computed: true,
Description: "Report id",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
}
Expand Down

0 comments on commit 2c5ec41

Please sign in to comment.