I have a SetNestedAttribute
which contains nested computed attributes -
"metric_fields": schema.SetNestedAttribute{
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"target_base_metric_name": schema.StringAttribute{
Required: true,
},
"source_field": schema.StringAttribute{
Required: true,
},
"aggregations": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Attributes: map[string]schema.Attribute{
"min": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.RequiresReplaceIfConfigured(),
},
Attributes: map[string]schema.Attribute{
"enable": schema.BoolAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
"target_metric_name": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
"max": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
Attributes: map[string]schema.Attribute{
"enable": schema.BoolAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
"target_metric_name": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
},
},
},
},
},
},
I wanted to avoid the plan phase to show updates from the existing state values, so I added UseStateForUnknown()
for all the computed attributes.
after applying the next config -
...
metric_fields = [
{
target_base_metric_name = "method"
source_field = "method"
},
{
target_base_metric_name = "geo_point"
source_field = "remote_addr_geoip.location_geopoint"
aggregations = {
max = {
enable = false
}
min = {
enable = false
}
}
}
]
...
I can see the state was configured correctly -
"metric_fields": [
{
"aggregations": {
"max": {
"enable": false,
"target_metric_name": "cx_max"
},
"min": {
"enable": false,
"target_metric_name": "cx_min"
},
},
"source_field": "remote_addr_geoip.location_geopoint",
"target_base_metric_name": "geo_point"
},
{
"aggregations": {
"max": {
"enable": true,
"target_metric_name": "cx_max"
},
"min": {
"enable": true,
"target_metric_name": "cx_min"
},
},
"source_field": "method",
"target_base_metric_name": "method"
}
],
However, when I run plan, it seems like the provider want to entirely replace the whole set -
~ metric_fields = [
- { # forces replacement
- aggregations = {
- max = {
- enable = false -> null
- target_metric_name = "cx_max" -> null
} -> null
- min = {
- enable = false -> null
- target_metric_name = "cx_min" -> null
} -> null
} -> null
- source_field = "remote_addr_geoip.location_geopoint" -> null
- target_base_metric_name = "geo_point" -> null
},
- { # forces replacement
- aggregations = {
- max = {
- enable = true -> null
- target_metric_name = "cx_max" -> null
} -> null
- min = {
- enable = true -> null
- target_metric_name = "cx_min" -> null
} -> null
- source_field = "method" -> null
- target_base_metric_name = "method" -> null
},
+ { # forces replacement
+ aggregations = {
+ max = {
+ enable = false
+ target_metric_name = (known after apply)
}
+ min = {
+ enable = false
+ target_metric_name = (known after apply)
}
}
+ source_field = "remote_addr_geoip.location_geopoint"
+ target_base_metric_name = "geo_point"
},
+ { # forces replacement
+ aggregations = {
+ max = {
+ enable = (known after apply)
+ target_metric_name = (known after apply)
} -> (known after apply)
+ min = {
+ enable = (known after apply)
+ target_metric_name = (known after apply)
} -> (known after apply)
} -> (known after apply)
+ source_field = "method"
+ target_base_metric_name = "method"
},
]
Beside that, it seems like it make the whole resource to be replaced -
coralogix_events2metric.logs2metric must be replaced
-/+ resource "coralogix_events2metric" "logs2metric" { ...
Is there something I can do to avoid this?