Provider implementation of only update operation

Hi all,
I am developing the citrixadc provider. (https://github.com/citrix/terraform-provider-citrixadc)
In this provider we use the HTTP REST API (NITRO) implemented to citrixadc to implement the terraform resources.
We have a sslparameter resource (https://developer-docs.citrix.com/projects/citrix-adc-nitro-api-reference/en/latest/configuration/ssl/sslparameter/) which has only UPDATE operation.
I tried to have a create and update functions as below:

func createSslparameterFunc(d *schema.ResourceData, meta interface{}) error {
// pseudo code below
Update the resource
readFunc(d, meta)
return nil
}

func updateSslparameterFunc(d *schema.ResourceData, meta interface{}) error {
//psuedo code below
check for hasChange
if hasChange {
Update the sslparameter
}
readFunc()
return nil
}

I can even use the same function for both create and update.

I am able to change (update) sslparameter resource, but getting the below error.

citrixadc_sslparameter.defalut: Creating...

Error: Provider produced inconsistent result after apply

When applying changes to citrixadc_sslparameter.defalut, provider
"registry.terraform.io/-/citrixadc" produced an unexpected new value for was
present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Where i am going wrong?

Thanks in advance

If the resource cannot be created via the provider, then you can’t let Terraform try to do it. You have to return an error of some sort, and require the user to ‘import’ the resource into the Terraform state so that update operations can be applied to it.

thank you @kpfleming for your quick reply.

Is it not possible to implement this without import ?

Also, I found out the reason of the error. (I guess)
I do not have id attribute in my resource. However, when I do terraform plan, the following plan is showing up.

# terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # citrixadc_sslparameter.default will be created
  + resource "citrixadc_sslparameter" "default" {
      + id       = (known after apply)
      + pushflag = 1
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

I do not know from where id attribute is showing up?

Also, I have removed d.SetId() as there is no ID present for this resource.

Terraform has to become aware of the resource’s existence somehow, and the resource must have an identifier. If the thing you are managing cannot be created by Terraform, can’t be imported into a Terraform, and doesn’t have an identifier, then it doesn’t match the requirements to be a ‘resource’ in Terraform and you’re going to struggle to implement it in your provider.

Thank you @kpfleming for your quick replies. Your suggestions helped me to write the resource.

1 Like