hashicorp / terraform-plugin-codegen-spec

Terraform Provider Code Generation Specification and Go Bindings
Mozilla Public License 2.0
7 stars 4 forks source link

Add `CustomPlanModifiers` and `CustomValidators` functions to all `PlanModifiers` and `Validators` types #77

Closed bendbennett closed 6 months ago

bendbennett commented 7 months ago

These changes are primarily to support updates in Remove attribute and block schema templates.

This PR adds convenience functions for obtaining CustomPlanModifiers and CustomValidators from PlanModifiers, and Validators types.

Additionally, convenience functions for obtaining CustomDefault from list, map, number, object, and set Default types have also been added.

For example:

BoolPlanModifiers

func (v BoolPlanModifiers) CustomPlanModifiers() CustomPlanModifiers {
    var customPlanModifiers CustomPlanModifiers

    for _, planModifier := range v {
        customPlanModifier := planModifier.Custom

        if customPlanModifier == nil {
            continue
        }

        customPlanModifiers = append(customPlanModifiers, customPlanModifier)
    }

    return customPlanModifiers
}

BoolValidators

func (v BoolValidators) CustomValidators() CustomValidators {
    var customValidators CustomValidators

    for _, validator := range v {
        customValidator := validator.Custom

        if customValidator == nil {
            continue
        }

        customValidators = append(customValidators, customValidator)
    }

    return customValidators
}

ListDefault

func (d *ListDefault) CustomDefault() *CustomDefault {
    if d == nil {
        return nil
    }

    return d.Custom
}
github-actions[bot] commented 1 month ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.