2 min read | by Jordi Prats
If we are modifying a provider, to be able to properly test it we might want to run a terraform plan or apply using this provider. To be able to override a given provider using this method (dev_overrides) we will need to use terraform v0.14 or later
First we will have to make sure we have the provider compiled. For example, to be able to complile the AWS provider we will need to use Go 1.17. To do so we can use the golang:1.17 docker container as follows:
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 go build -o terraform-provider-aws_v9.9.9
Once is is compiled we will see that it has created a file named, in this case, terraform-provider-aws_v9.9.9. To tell terraform to use it instead of the registry's version we will have to create a dev_overrides.
You'll have to create file (for example dev.tfrc) containing the following:
provider_installation {
dev_overrides {
"hashicorp/aws" = "/home/pet2cattle/github/terraform-provider-aws"
}
# all the other providers, install them as usual
direct {}
}
This override tells terraform that for hashicorp/aws it can find the provider on that path. Now we will have to tell terraform to use this config file, to do so we need to set the TF_CLI_CONFIG_FILE variable with the path to that file. So, to do a terraform plan overriding a the provider we can run it as follows:
TF_CLI_CONFIG_FILE=dev.tfrc terraform plan
On the terraform's output we will see the following message that tells us that dev_overrides are actually in effect:
$ TF_CLI_CONFIG_FILE=dev.tfrc terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│ - hashicorp/aws in /home/pet2cattle/github/terraform-provider-aws_data_sgs
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
Acquiring state lock. This may take a few moments...
(...)
Posted on 14/10/2021