auth0 / terraform-provider-auth0

The Auth0 Terraform Provider is the official plugin for managing Auth0 tenant configuration through the Terraform tool.
https://registry.terraform.io/providers/auth0/auth0/latest/docs
Mozilla Public License 2.0
165 stars 83 forks source link

`tf generate` does not create a auth0_generated.tf file. `terraform plan` fails #936

Closed zaphod72 closed 7 months ago

zaphod72 commented 7 months ago

Checklist

Description

Starting with an empty dir. I run

> export AUTH0_DOMAIN=<tenant>.us.auth0.com
> export AUTH0_CLIENT_ID=<M2M client ID>
> export AUTH0_CLIENT_SECRET=<M2M client secret>

> auth0 --debug tf generate
Fetching data from Auth0... done
Generating Terraform configuration... failed
 ▸    Terraform resource config generated successfully but there was an error with terraform plan.

 ▸    Run ./terraform plan to troubleshoot

 ▸    Once the plan succeeds, run ./terraform apply to complete the import.

 ▸    The terraform binary and auth0_import.tf files can be deleted afterwards.

> ls -al
total 139016
drwxr-xr-x  7 darrenk  staff       224 Mar 21 17:52 .
drwxr-xr-x@ 3 darrenk  staff        96 Mar 21 13:21 ..
drwxr-xr-x@ 3 darrenk  staff        96 Mar 21 17:52 .terraform
-rw-r--r--@ 1 darrenk  staff      1330 Mar 21 17:52 .terraform.lock.hcl
-rw-r--r--@ 1 darrenk  staff      5189 Mar 21 17:52 auth0_import.tf
-rw-r--r--@ 1 darrenk  staff       187 Mar 21 17:52 auth0_main.tf
-rwx------@ 1 darrenk  staff  71156112 Mar 21 17:52 terraform
> DEBUG=1 ./terraform plan

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Import block target does not exist
│ 
│   on auth0_import.tf line 5:
│    5: import {
│ 
│ The target for the given import block does not exist. If you wish to automatically generate config for this resource, use the -generate-config-out option within terraform plan. Otherwise, make sure the target resource exists within your configuration. For
│ example:
│ 
│   terraform plan -generate-config-out=generated.tf

The Import block error repeats for every item in the auth0_import.tf file.

No auth0_generated.tf file exists.

Expectation

Generating Terraform configuration... failed would be successful and all necessary .tf files generated.

Reproduction

Followed creation of M2M application as per https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/quickstart#create-a-machine-to-machine-application

Double-checked the exported AUTH0 env vars are correct.

Followed instructions at https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/generate_terraform_config

Auth0 Terraform Provider version

1.5.0

Terraform version

1.7.4

zaphod72 commented 7 months ago

auth0 version 1.4.0 54e9a30eeb58a4a7e40e04dc19af6869036bfb32

zaphod72 commented 7 months ago

Fix: Ran the auth0 commands from an empty dir.

Cause: Was running auth0 CLI commands from the root dir of a next.js project, containing .env.local and other config files that may have messed with the auth0 CLI.

alfechner commented 6 months ago

@zaphod72,I had the same issue and thanks to your post I realised that I messed up the credentials in the env variables.

tailaiw commented 2 months ago

@zaphod72 I have the same issue (same version, auth0 version 1.4.0 54e9a30eeb58a4a7e40e04dc19af6869036bfb32), and I tried to run in an empty directory, but still the same issue

❯ mkdir foo
❯ cd foo
❯ auth0 tf generate --output-dir tmp-auth0-tf
Fetching data from Auth0... done
Generating Terraform configuration... failed
 ▸    Terraform resource config generated successfully but there was an error with terraform plan.

 ▸    Run cd tmp-auth0-tf && ./terraform plan to troubleshoot

 ▸    Once the plan succeeds, run ./terraform apply to complete the import.

 ▸    The terraform binary and auth0_import.tf files can be deleted afterwards.

The auth0_import.tf file looks right to me, but the auth0_main.tf only have provider block

terraform {
  required_version = "~> 1.5.0"
  required_providers {
    auth0 = {
      source  = "auth0/auth0"
      version = ">= 1.0.0"
    }
  }
}

provider "auth0" {
  debug = true
}