func convertPolicyAssignmentParametersMapToSdkType()

in internal/provider/architecture_data_source.go [568:612]


func convertPolicyAssignmentParametersMapToSdkType(src types.Map, resp *datasource.ReadResponse) map[string]*armpolicy.ParameterValuesValue {
	if !isKnown(src) {
		return nil
	}
	result := make(map[string]*armpolicy.ParameterValuesValue)
	for k, v := range src.Elements() {
		// Even thought he schema type is identical, from policy assignments to modify we receive basetypes.String values,
		// but from policy default values we receive jsontypes.Noprmalized.
		// We convert to Terraform value to get the string representation.
		vTf, err := v.ToTerraformValue(context.Background())
		if err != nil {
			resp.Diagnostics.AddError(
				"convertPolicyAssignmentParametersMapToSdkType: error",
				"unable to convert parameter value to Terraform value",
			)
			return nil
		}
		var vStr string
		err = vTf.Copy().As(&vStr)
		if err != nil {
			resp.Diagnostics.AddError(
				"convertPolicyAssignmentParametersMapToSdkType: error",
				"unable to convert parameter value to string",
			)
			return nil
		}
		var pv armpolicy.ParameterValuesValue
		if err := pv.UnmarshalJSON([]byte(vStr)); err != nil {
			resp.Diagnostics.AddError(
				"convertPolicyAssignmentParametersMapToSdkType: error",
				fmt.Sprintf("unable to unmarshal policy parameter value: %s", err.Error()),
			)
			return nil
		}
		if pv.Value == nil {
			resp.Diagnostics.AddError(
				"convertPolicyAssignmentParametersMapToSdkType: error",
				fmt.Sprintf("policy parameter `%s` value is nil, make sure to supply parameter value as follows: `jsonencode({ value = \"foo\" })`, or `jsonencode({ value = 1 })`", k),
			)
			return nil
		}
		result[k] = &pv
	}
	return result
}