func()

in ec/ecresource/deploymentresource/elasticsearch/v2/node_roles_plan_modifier.go [90:137]


func (m setUnknownOnTopologyChanges) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) {
	if req.PlanValue.IsUnknown() || req.PlanValue.IsNull() {
		return
	}

	for _, tierName := range tierNames {
		var tierValue attr.Value
		resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("elasticsearch").AtName(tierName), &tierValue)...)
		if resp.Diagnostics.HasError() {
			return
		}

		for _, attrName := range sizingAttributes {
			attrPath := path.Root("elasticsearch").AtName(tierName).AtName(attrName)
			var planValue attr.Value
			resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, attrPath, &planValue)...)
			if resp.Diagnostics.HasError() {
				return
			}

			var stateValue attr.Value

			resp.Diagnostics.Append(req.State.GetAttribute(ctx, attrPath, &stateValue)...)
			if resp.Diagnostics.HasError() {
				return
			}

			// If the plan value is unknown then planmodifiers haven't run for this topology element
			// Eventually the plan value will be set to the state value and it will be unchanged.
			// The tier should be directly checked for unknown, since the planValue will be null in that case (instead of unknown).
			// See: https://github.com/hashicorp/terraform-plugin-framework/issues/186
			if (planValue.IsUnknown() || tierValue.IsUnknown()) && !(stateValue.IsUnknown() || stateValue.IsNull()) {
				continue
			}

			hasChanged, diags := planmodifiers.AttributeChanged(ctx, attrPath, req.Plan, req.State)
			resp.Diagnostics.Append(diags...)
			if resp.Diagnostics.HasError() {
				return
			}

			if hasChanged {
				resp.PlanValue = types.SetUnknown(types.StringType)
				return
			}
		}
	}
}