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

Support Terraform Cloud with different workspaces #150

Open
raspbeguy opened this issue Jun 12, 2024 · 2 comments · May be fixed by #163
Open

Support Terraform Cloud with different workspaces #150

raspbeguy opened this issue Jun 12, 2024 · 2 comments · May be fixed by #163
Labels
type/bug Something isn't working verified

Comments

@raspbeguy
Copy link

SUMMARY

As I understand there is two way to build an inventory using terraform states:

  • cloud.terraform.terraform_state to query directly a state backend using provided backend configuration
  • cloud.terraform.terraform_provider to query stated through local terraform project

I didn't manage to use terraform_state, with the following configuration:

plugin: cloud.terraform.terraform_state
hostname: terraform.mydomain.example
backend_type: remote
backend_config:
  organization: my-org
  workspaces:
    name: my-workspace

For that reason I'm using Terraform Cloud with multiple workspaces. For now I'm successfully using terraform_provider. My terraform configuration looks like this:

terraform {
  cloud {
    hostname = "terraform.mydomain.examples"
    organization = "my-org"

    workspaces {
      tags = ["tag1", "tag2"]
    }
  }
  ...
}

I use tags instead of workspace parameter to enable using several workspaces.

The problem with terraform_provider is that I have to manually switch to the desired workspace by typing:

terraform workspace select myworkspace

I would rather have an option in terraform_provider to specify the workspace.

Another option would be to make terraform_state work with the remote option.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME
  • cloud.terraform.terraform_state
  • cloud.terraform.terraform_provider
@gravesm
Copy link
Member

gravesm commented Jun 17, 2024

What is the error message you are receiving when using the terraform_state plugin? Also, what version of the cloud.terraform collection and Ansible are you using?

@gravesm gravesm added the needs_info Needs additional information from original reporter label Jun 17, 2024
@raspbeguy
Copy link
Author

I'm using master version on the plugins.

I have got this error:

[WARNING]:  * Failed to parse /home/ggodfroy/repo/metrics-infra/ansible/environments/preprod-test/terraform_state.yml with auto plugin: Command '['tofu', 'init', '-input=false', '-no-color', '-backend-config',
'hostname=terraform.mydomain.examples', '-backend-config', 'organization=my-org', '-backend-config', "workspaces={'name': 'my-workspace'}"]' returned non-zero exit status 1.

When I execute this tofu command myself I get this error:

OpenTofu initialized in an empty directory!

The directory has no OpenTofu configuration files. You may begin working
with OpenTofu immediately by creating OpenTofu configuration files.

I guess there is no way to change directory in terraform_state. Also I don't know why I functionally would need some terraform/tofu config because I normally provided everything the plugin needs to fetch states.

Same error with tofu and terraform btw.

@gravesm gravesm added type/bug Something isn't working verified and removed needs_info Needs additional information from original reporter labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants