Use null values in custom terraform provider as a new state

56 Views Asked by At

I'm developing a new custom terrafrom provider using the terraform plugin framework. In the API, we have a nullable integer value (e.g. someVar can be an integer from 1 to 1000 or null). I've used this definiton for the someVar in the schema defintion:

"someVar": schema.Int64Attribute{
    Optional: true,
    Computed: true,
    Validators: []validator.Int64{
    int64validator.Between(1, 1000),
    },
},

In the .tf file i've used this:

someVar = 500

And later

someVar = null

The problem is the change to null for someVar is not being detected when using terraform plan or terraform apply.

I've tested PlanModifier (ResourceWithModifyPlan) to detect the null value but the problem is the result of isNull() for someVar is always false.

var plan myResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)

if resp.Diagnostics.HasError() {
    return
}

// plan.someVar.isNull() -> false

What am I missing here?

0

There are 0 best solutions below