-
Notifications
You must be signed in to change notification settings - Fork 458
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
terraform.workspace
equivalent
#376
Comments
I was chatting with @jsteinich about this yesterday... I was going to open an issue this morning, but you beat me to it :) Not sure if you're seeing the exact same thing as me, but there are situations where the cdktf-cli hangs when Terraform prompts about workspaces. Here's an example:
Sorry to conflate these, but I think this is generally related to another problem I've seen initializing state with
|
Hm, I thought Which version are you running? |
The interpolation itself should just work: new Instance(this, 'aws instance', {
name: "web - ${terraform.workspace}"
}) Could you elaborate on the use-case you're trying to solve? |
Debug output shows I was using:
|
Hm, interesting. Well, that's something to investigate then, but it's probably a separate issue? |
@skorfmann I understand the interpolation - maybe it's just that I couldn't find the My workaround was that I was setting up the const workspaceName = process.env.WORKSPACE || 'dev'
new Instance(this, 'aws instance', {
name: "web - ${workspaceName}"
})
new RemoteBackend(stack, {
organization: 'pontifex',
workspaces: {
name: workspaceName
},
}); Then I can reuse the Just seeing if this was the current recommended? Or similar to how we would do |
@damienpontifex |
@damienpontifex what you're looking for is 1st class support Terraform workspaces in |
Something like that @skorfmann. |
We are using the following approach to access workspace in the code:
|
This would be pretty simple to add after #525 is completed. |
Hi, on which folder are you executing the cdk synth command?, I mean in the cdktf.out folder or if you have an example about the folder structure to have this approach, I tried but the workspace that I'm getting is default |
I think this is something that would be good to have better built in support for, but I'm not aware of any planned work as of yet. |
Hi @javier-caylent! Since CDKTF generate stack to run it with terraform it's important in which folder to run command to switch workspace, for example The full flow:
|
Awesome, You help me a lot with this information. Thank you very much!!! @nick0lay. |
Welcome! There is one more thing which you might be aware of. Even though that you have access to workspace in Terrafrom CDKTF
Hence when you use
But switching workspace still might be useful if you use |
Hi @nick0lay hmm, got it, I think that we can "emulate" the ${terraform.workspace}, sending the environment for each stack and get the variables values in the same way. I'll test it and see, how works this approach and the s3 remote state (S3Backend) and where will be store the tfstate file for each stack.
|
Community Note
Description
Searching around and I couldn't find an equivalent for Current Workspace Interpolation in terraform-cdk. Currently we use this in terraform for environment suffixes and would be nice to transfer that capability across to our usage with cdktf
The text was updated successfully, but these errors were encountered: