Since CIDR is immutable via API, applying the same over here.
The CustomizeDiff function allows us to perform custom validation during the diff phase and can be used to detect changes to the cidr_v4 field and return an error if a change is detected.
This would throw an error in the planning phase itself.
The below change will throw error error when terraform apply is done hence this approach is not preferable.
func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
apiClient := m.(*civogo.Client)
// overwrite the region if is defined in the datasource
if region, ok := d.GetOk("region"); ok {
apiClient.Region = region.(string)
}
if d.HasChange("cidr_v4") {
return diag.Errorf("the 'cidr_v4' field is immutable")
}
if d.HasChange("label") {
log.Printf("[INFO] updating the network %s", d.Id())
_, err := apiClient.RenameNetwork(d.Get("label").(string), d.Id())
if err != nil {
return diag.Errorf("[ERR] An error occurred while rename the network %s", d.Id())
}
return resourceNetworkRead(ctx, d, m)
}
return resourceNetworkRead(ctx, d, m)
}
Fixes: #233
Since CIDR is immutable via API, applying the same over here. The
CustomizeDiff
function allows us to perform custom validation during the diff phase and can be used to detect changes to thecidr_v4
field and return an error if a change is detected.This would throw an error in the planning phase itself.
The below change will throw error error when terraform apply is done hence this approach is not preferable.