Skip to content

SetDefaultEnvVar

This plan modifier is used to set a default value for a boolean from an environment variable.

How to use it

export CAV_VAR_DEFAULT_NAME="true"
// Schema defines the schema for the resource.
func (r *vappResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{
        (...)
            "enabled": schema.BoolAttribute{
                Optional:            true,
                MarkdownDescription: "",
                PlanModifiers: []planmodifier.Bool{
                    fboolplanmodifier.SetDefaultEnvVar("CAV_VAR_DEFAULT_NAME"),
                },
            },