Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terraform): improve init behaviour on validate and error messages #3663

Merged
merged 1 commit into from Feb 2, 2023

Conversation

10ko
Copy link
Member

@10ko 10ko commented Feb 2, 2023

What this PR does / why we need it:

Improve the behaviour around validation and init for the terraform provider. We now always run terraform init if terraform validate fails and we display the different error messages accordingly.

Example of error message:

emanuele  terraform-gke   fix-terraform-init-behaviour ±  g validate -l4 --force-refresh
Validate ✔️ 

[debug] Cloud/Enterprise domain not configured. Aborting.

[debug] Error reading safe directories from the .gitconfig: Error: Command "git config --get-all safe.directory" failed with code 1:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🌍  Running in namespace default in environment local
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[debug] Scanning project root at /Users/emanuele/code/garden/examples/terraform-gke
→ Includes: **/*garden.y*ml
→ Excludes: .garden/**/*,.git,.gitmodules,.garden/**/*,debug-info*/**
[debug] Found 1 files in project root /Users/emanuele/code/garden/examples/terraform-gke
ℹ providers                 → Getting status...
ℹ local-kubernetes [debug]  → Using detected context: docker-desktop
ℹ providers [debug]         → An attempt to get kind version failed with Error: Command "kind version" failed with code ENOENT:
ℹ providers [debug]         → Kubernetes: Getting API resource info for group networking.k8s.io/v1
ℹ garden system [debug]     → Initializing...
ℹ garden system [debug]     → Error reading safe directories from the .gitconfig: Error: Command "git config --get-all safe.directory" failed with code 1:
ℹ providers                 → Getting status...
ℹ providers [debug]         → Validation failed, trying to run "terraform init".
ℹ providers [debug]         → An attempt to get kind version failed with Error: Command "kind version" failed with code ENOENT:
✔ providers                 → Getting status... → Cached
ℹ providers                 → Run with --force-refresh to force a refresh of provider statuses.
ℹ garden system [debug]     → Scanning project root at /Users/emanuele/code/garden/static/kubernetes/system
→ Includes: **/*garden.y*ml
→ Excludes: ../../../examples/terraform-gke/.garden/kubernetes.garden/**/*,.git,.gitmodules,.garden/**/*,debug-info*/**
ℹ garden system [debug]     → Found 11 files in project root /Users/emanuele/code/garden/static/kubernetes/system
ℹ graph                     → Resolving 11 modules...
✔ graph                     → Resolving 11 modules... → Done
ℹ providers [debug]         → Kubernetes: Getting API resource info for group apps/v1
ℹ providers [debug]         → Kubernetes: Getting API resource info for group v1
ℹ providers [debug]         → Getting currently deployed resource statuses...
ℹ providers [debug]         → Terraform init failed with error: ${error.message}

Failed resolving provider terraform. Here is the output:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Failed validating Terraform configuration:

Error: Missing required provider
This configuration requires provider registry.terraform.io/hashicorp/azurermaaaa, but that provider isn't available. You may be able to install it automatically by running:
terraform init

Garden tried running "terraform init" but got the following error:

Command "/Users/emanuele/.garden/tools/terraform-1-2-9/bcf17392a2ac5e7c/terraform init" failed with code 1:


│ Error: Failed to query available provider packages

│ Could not retrieve the list of available versions for provider
│ hashicorp/azurermaaaa: provider registry registry.terraform.io does not
│ have a provider named registry.terraform.io/hashicorp/azurermaaaa

│ All modules should specify their required_providers so that external
│ consumers will get the correct providers when using a module. To see which
│ modules are currently depending on hashicorp/azurermaaaa, run the following
│ command:
│     terraform providers



Here's the full output:


Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurermaaaa versions matching "3.41.0"...
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider
│ hashicorp/azurermaaaa: provider registry registry.terraform.io does not
│ have a provider named registry.terraform.io/hashicorp/azurermaaaa
│ 
│ All modules should specify their required_providers so that external
│ consumers will get the correct providers when using a module. To see which
│ modules are currently depending on hashicorp/azurermaaaa, run the following
│ command:
│     terraform providers
╵

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ providers [verbose]       → Comparing expected and deployed resources...
ℹ providers [verbose]       → All resources match.
✔ garden system [debug]     → Initializing...
[debug] Done flushing all events and log entries.
Failed resolving one or more providers:
- terraform

See .garden/error.log for detailed error message
  providers                 → Getting status...
[debug] Done flushing all events and log entries.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Copy link
Member

@stefreak stefreak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for working on this :) This should be much more robust now 👍

Copy link
Collaborator

@twelvemo twelvemo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 More robust and it will be more helpful for debuggin why a terraform stack isn't valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants