Comments (6)
Hello @mcassaniti, can you share the workflow yaml you are using and the workflow log output? What is it you expect to happen that is not working?
The validate
command is only doing static checking of the module, I wouldn't expect the terraform.workspace
to be evaluated or the provider actually initialised. The snippet you provided seems to validate for me.
from terraform-github-actions.
Thank you for getting back to me so soon.
Workflow code.
---
name: agent-monitoring
on:
pull_request:
paths:
- agent-monitoring/**
jobs:
plan:
name: Test agent-monitoring
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Create Hashicorp vault password file
run: echo ${{ secrets.HASHICORP_VAULT_ANSIBLE_PASSWORD }} > .vault_password
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_KEY }}
aws-region: ap-southeast-2
- name: Create Terraform workspace
uses: dflook/terraform-new-workspace@v1
with:
path: agent-monitoring
workspace: prod
- name: Validate Terraform
uses: dflook/terraform-validate@v1
with:
path: agent-monitoring
- name: Plan Terraform
uses: dflook/terraform-plan@v1
with:
path: agent-monitoring
workspace: prod
add_github_comment: false
From the workflow run using the YAML above, create terraform workspace step.
Initializing modules...
- lambda_python_package in ../_common-modules/lambda-python-archive
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/vault from the dependency lock file
- Reusing previous version of hashicorp/external from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Installing hashicorp/aws v3.66.0...
- Installed hashicorp/aws v3.66.0 (signed by HashiCorp)
- Installing hashicorp/vault v2.24.1...
- Installed hashicorp/vault v2.24.1 (signed by HashiCorp)
- Installing hashicorp/external v2.1.0...
- Installed hashicorp/external v2.1.0 (signed by HashiCorp)
- Installing hashicorp/random v3.1.0...
- Installed hashicorp/random v3.1.0 (signed by HashiCorp)
Terraform has been successfully initialized!
Workspace appears to exist, selecting it
Switched to workspace "prod".
From the workflow run using the YAML above, validate terraform step.
Initializing modules...
- lambda_python_package in ../_common-modules/lambda-python-archive
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/vault from the dependency lock file
- Reusing previous version of hashicorp/external from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Using hashicorp/random v3.1.0 from the shared cache directory
- Using hashicorp/aws v3.66.0 from the shared cache directory
- Using hashicorp/vault v2.24.1 from the shared cache directory
- Using hashicorp/external v2.1.0 from the shared cache directory
Terraform has been successfully initialized!
Error: Invalid index
Error: Invalid index
╷
│ Error: Invalid index
│
│ on providers.tf line 41, in provider "aws":
│ 41: region = local.aws_provider_config[terraform.workspace].region
│ ├────────────────
│ │ local.aws_provider_config is object with 2 attributes
│ │ terraform.workspace is "default"
│
│ The given key does not identify an element in this collection value.
╵
╷
│ Error: Invalid index
│
│ on providers.tf line 42, in provider "aws":
│ 42: allowed_account_ids = [local.aws_provider_config[terraform.workspace].account_id]
│ ├────────────────
│ │ local.aws_provider_config is object with 2 attributes
│ │ terraform.workspace is "default"
│
│ The given key does not identify an element in this collection value.
╵
Output when run in a fresh directory after a clone and setup of credentials.
mcassaniti@wks-mcass-linux:~/test-this/agent-monitoring$ terraform init
Initializing modules...
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/external from the dependency lock file
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/vault from the dependency lock file
- Installing hashicorp/random v3.1.0...
- Installed hashicorp/random v3.1.0 (signed by HashiCorp)
- Installing hashicorp/external v2.1.0...
- Installed hashicorp/external v2.1.0 (signed by HashiCorp)
- Installing hashicorp/aws v3.66.0...
- Installed hashicorp/aws v3.66.0 (signed by HashiCorp)
- Installing hashicorp/vault v2.24.1...
- Installed hashicorp/vault v2.24.1 (signed by HashiCorp)
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.
mcassaniti@wks-mcass-linux:~/test-this/agent-monitoring$ terraform validate
╷
│ Error: Invalid index
│
│ on providers.tf line 41, in provider "aws":
│ 41: region = local.aws_provider_config[terraform.workspace].region
│ ├────────────────
│ │ local.aws_provider_config is object with 2 attributes
│ │ terraform.workspace is "default"
│
│ The given key does not identify an element in this collection value.
╵
╷
│ Error: Invalid index
│
│ on providers.tf line 42, in provider "aws":
│ 42: allowed_account_ids = [local.aws_provider_config[terraform.workspace].account_id]
│ ├────────────────
│ │ local.aws_provider_config is object with 2 attributes
│ │ terraform.workspace is "default"
│
│ The given key does not identify an element in this collection value.
╵
mcassaniti@wks-mcass-linux:~/test-this/agent-monitoring$
from terraform-github-actions.
What version of terraform are you using?
from terraform-github-actions.
Local version:
mcassaniti@wks-mcass-linux:/mnt/data/GIT/test-this/agent-monitoring$ terraform --version
Terraform v1.0.11
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.66.0
+ provider registry.terraform.io/hashicorp/external v2.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/hashicorp/vault v2.24.1
mcassaniti@wks-mcass-linux:/mnt/data/GIT/test-this/agent-monitoring$
Workflow version:
Installing Terraform
Reading latest terraform version
Switched terraform to version "1.0.11"
from terraform-github-actions.
Hi @mcassaniti, there is a new version v1.21.0 that has a new workspace
input for the dflook/terraform-validate
action.
I was mistaken in that terraform.workspace
is evaluated, but terraform doesn't initialise it properly when doing a validate.
Using the new workspace
input you can set the full name of the workspace to use while validating.
For the S3 backend this should match the workspace name you normally use.
from terraform-github-actions.
Thank you so much and thanks for the quick turnaround.
from terraform-github-actions.
Related Issues (20)
- Cannot run plan with S3 backend HOT 4
- Inability to trigger the action due to an alleged missing file HOT 5
- Terraform Plan action fails due to Unknown token: 15:19 IDENT confluent_service_account.app-producer.id error HOT 10
- "terraform-plan" fails with an error while using "terraform plan" succeeds HOT 2
- backend_config read as file in apply
- Ability to Share Plan Outputs Between Runs HOT 6
- Resources are not removed despite the action claiming otherwise HOT 2
- Issues in terraform version 1.6.0 HOT 1
- Support for Terraform 1.6 test framework
- Terraform Cloud deploy with hard-coded workspace fails
- Add option to create new comments on following execution of a terraform operation HOT 3
- OpenTofu support HOT 5
- Terraform Plan Action failing on tf version 1.6.x showing S3 403 permission error
- terraform-plan error: The process '/usr/bin/git' failed with exit code 128 HOT 2
- Terraform Plan Fails on self-hosted runner - ls: cannot access '/github/home': No such file or directory HOT 12
- .tool-versions at workspace level doesn't work HOT 1
- Terraform Cloud backend requires manual "Confirm & Apply" for Terraform >= 1.6.0 HOT 6
- Add option for multiple SSH keys (GH deploy keys)
- auto apply if no resources changed HOT 1
- Impossible to update to a newer terraform version if only the GitHub Action is allowed to execute terraform HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-github-actions.