aequitas/terraform-provider-transip

Error: failed to create token cache dir when using transip module from terraform docker container

Closed this issue · 3 comments

Hi,

Struggled a bit this morning to get the transip module working in a container using the official terraform docker container. Steps to reproduce:

$ ls
.           ..          foo_bar.key main.tf
$ cat main.tf
terraform {
  required_providers {
    transip = {
      source  = "aequitas/transip"
      version = "~> 0.1.10"
    }
  }
}

provider "transip" {
  account_name = "foo_bar"
  private_key  = file("foo_bar.key")
}

resource "transip_domain" "example_org" {
  name = "example.org"
}
$ docker run --platform linux/x86_64 --rm -it -w /code -v $PWD:/code \
  --entrypoint /bin/ash docker.io/hashicorp/terraform:1.0.7
/code # terraform init

Initializing the backend...

Initializing provider plugins...
- Finding aequitas/transip versions matching "~> 0.1.10"...
- Installing aequitas/transip v0.1.10...
- Installed aequitas/transip v0.1.10 (self-signed, key ID B1AE6948ED49BB55)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
/code # terraform plan
╷
│ Error: failed to create token cache dir
│
│   with provider["registry.terraform.io/aequitas/transip"],
│   on main.tf line 10, in provider "transip":
│   10: provider "transip" {
│
╵

To fix it "simply" create the cacheDir as described here:

cacheFile := filepath.Join(cacheDir, "gotransip_test_token_cache")

/code # mkdir ~/.cache
/code # terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # transip_domain.example_org will be created
  + resource "transip_domain" "example_org" {
      + id   = (known after apply)
      + name = "example.org"
    }

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

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

I'll create a pull request to create the directory if it does not exist

I was thinking of replacing the cache file with an in memory file. As that would get rid of all kinds of issues that you can have with real files. But that would probably require a change in the gotransip module itself so I don't know when that will be ready. But if you have a short term workaround I'm glad to merge the PR.

@aequitas agree that that would be a better solution for now I have posted a workaround and will leave the gotransip module to you ;)

Merged your solution, will push a release soon. Thanks for helping out.