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!