Update is not run on change of computed variable

Hi, I am currently developing a custom terraform provider using the sdk v2. I have the following variables:

func ResourcePushImage() *schema.Resource {
	return &schema.Resource{
		CreateContext: resourcePushImageCreate,
		DeleteContext: resourcePushImageDelete,
		UpdateContext: resourcePushImageUpdate,
		ReadContext: resourcePushImageRead,
		Schema: map[string]*schema.Schema{
				"ecr_repository_name": {
					Type:        schema.TypeString,
					Required:    true,
					Description: "The name of your ECR repository",
				},
				"dockerfile_path": {
					Type:        schema.TypeString,
					Optional:    true,
					Default:     ".",
					Description: "The path to the Dockerfile. Dockerfiles must always be called 'Dockerfile'",
				},
				"image_name": {
					Type: schema.TypeString,
					Required: true,
					Description: "The name of the Docker image",
				},
				"image_tag": {
					Type: schema.TypeString,
					Required: true, 
					Description: "The tag of the Docker image",
				},
				"dockerfile_hash" : {
					Type: schema.TypeString,
					Computed: true,
					Optional: true,
					Description: "Do not set this field, it is for internal use only",
				},
		},
	}
}

The idea is that, if the content of the Dockerfile changes, the image should be recomputed, if terraform apply is rerun. To gather the content of the Dockerfile, it is read and then hashed. However if I make changes to it and run terraform apply again, terraform does not register any changes.

I have implemented this in the Read function, to gather the potentially new hash of the Dockerfile

	dockerfileHash, err := getDockerfileHash(dockerfilePath)
	if err != nil {
		return diag.FromErr(fmt.Errorf("error reading Dockerfile: %s", err))
	}
	d.Set("dockerfile_hash", dockerfileHash)

The update function contains this line with the code to update:

if d.HasChange("dockerfile_hash") {

Has somebody a clue why the changes to the Dockerfile are not registered? The hashing code works perfectly.
Thank you!

Hi @dominikhei01,

Something to keep in mind, if you are developing a new provider, I would suggest using the current provider framework. The legacy SDKv2 is descended from pre-0.12 terraform, and has many known issues that you will need to work around.

It’s not clear what you are trying to detect, or what you need to recompute in the given scenario, a more complete example would help here.

Is dockerfile_hash set in the configuration? If it’s not configured, there is no change to detect, because there is no configuration to impose a change. If dockerfile_hash is entirely computed, it probably shouldn’t be Optional in the schema. If you could detect a change in dockerfile_hash, what exactly is it you plan to do? There are no other computed attributes, so it’s not clear what you mean by “recomputed”.