Skip to content

Commit 2c5ec41

Browse files
committed
add plan modifier to avoid replacement when there is an update
1 parent 91aa879 commit 2c5ec41

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

examples/main.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ terraform {
66
}
77
}
88
}
9+
resource "doit_attribution" "attri" {
10+
name = "attritestnewname"
11+
description = "attritestdesc"
12+
formula = "A"
13+
components = [{ type = "label", key = "iris_region", values = ["us-central1"] }]
14+
}
15+
16+
resource "doit_attribution_group" "attributeGroup" {
17+
name = "attritestnewgroup"
18+
description = "attritestgroup-new-new"
19+
attributions = [doit_attribution.attri.id]
20+
}
921

1022
resource "doit_report" "my-report_january" {
1123
name = "my-report"
@@ -15,7 +27,7 @@ resource "doit_report" "my-report_january" {
1527
type = "basic"
1628
value = "cost"
1729
}
18-
sort_groups = "asc"
30+
sort_groups = "asc"
1931
sort_dimensions = "asc"
2032
advanced_analysis = {
2133
trending_up = true

internal/provider/attribution_group_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/hashicorp/terraform-plugin-framework/resource"
1212
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
14+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1315
"github.com/hashicorp/terraform-plugin-framework/types"
1416
)
1517

@@ -52,6 +54,9 @@ func (r *attributionGroupResource) Schema(ctx context.Context, _ resource.Schema
5254
"id": schema.StringAttribute{
5355
Description: "Numeric identifier of the attribution group",
5456
Computed: true,
57+
PlanModifiers: []planmodifier.String{
58+
stringplanmodifier.UseStateForUnknown(),
59+
},
5560
},
5661
"last_updated": schema.StringAttribute{
5762
Description: "Timestamp of the last Terraform update of" +

internal/provider/attribution_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-framework/resource"
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1214
"github.com/hashicorp/terraform-plugin-framework/types"
1315
)
1416

@@ -59,6 +61,9 @@ func (r *attributionResource) Schema(_ context.Context, _ resource.SchemaRequest
5961
"id": schema.StringAttribute{
6062
Description: "Numeric identifier of the attribution",
6163
Computed: true,
64+
PlanModifiers: []planmodifier.String{
65+
stringplanmodifier.UseStateForUnknown(),
66+
},
6267
},
6368
"last_updated": schema.StringAttribute{
6469
Description: "Timestamp of the last Terraform update of" +

internal/provider/report_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1617
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
18+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1719
"github.com/hashicorp/terraform-plugin-framework/types"
1820
)
1921

@@ -561,6 +563,9 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res
561563
"id": schema.StringAttribute{
562564
Computed: true,
563565
Description: "Report id",
566+
PlanModifiers: []planmodifier.String{
567+
stringplanmodifier.UseStateForUnknown(),
568+
},
564569
},
565570
},
566571
}

0 commit comments

Comments
 (0)