[英]command to list workspaces and aws resources created using workspace
Hi I am new to terraform. I want to list resources of aws and correspoding workspace for that resource.您好,我是 terraform 的新手。我想列出 aws 资源和该资源的相应工作空间。 I know that terraform
terraform workspace list
will give each workspace.我知道 terraform
terraform workspace list
会给出每个工作空间。
When listing the states its not giving exact information of which resources were created by terraform workspace.在列出状态时,它没有给出 terraform 工作空间创建了哪些资源的确切信息。
terraform state list
any script or command we have to display just workspace and resource created byt that workspace?我们必须只显示工作区和该工作区创建的资源的任何脚本或命令吗? nothing else.
没有其他的。
From the docs:从文档:
Workspaces allow you to use the same working copy of your configuration and the same plugin and module caches, while still keeping separate states for each collection of resources you manage.
工作区允许您使用配置的相同工作副本以及相同的插件和模块缓存,同时仍然为您管理的每个资源集合保持单独的状态。
And then然后
Workspaces are technically equivalent to renaming your state file.
工作区在技术上等同于重命名您的 state 文件。 They aren't any more complex than that.
它们并不比这更复杂。 Terraform wraps this simple notion with a set of protections and support for remote state.
Terraform 用一组保护和支持远程 state 来包装这个简单的概念。
In other words, you might be misunderstanding how workspaces and state list
works because换句话说,您可能会误解工作区和
state list
工作方式,因为
The
terraform state list
command can list the resources being managed by the current working directory and workspace, providing a complete or filtered list .terraform state list
命令可以列出当前工作目录和工作空间所管理的资源,提供完整的或过滤后的列表。
And the most important part is this最重要的部分是这个
The command will list all resources in the state file matching the given addresses (if any).
该命令将列出 state 文件中与给定地址(如果有)匹配的所有资源。 If no addresses are given, all resources are listed.
如果没有给出地址,则列出所有资源。
TLDR; TLDR;
There's no such extra command because utilizing workspaces
and terraform state list
should meet your requirements.没有这样的额外命令,因为使用
workspaces
和terraform state list
应该可以满足您的要求。
Selecting a given workspace and then terraform state show
will give you all the resources for that workspace only.选择给定的工作区,然后
terraform state show
将为您提供该工作区的所有资源。
To list the Terraform workspaces, you can use the terraform workspace list command:要列出 Terraform 工作区,可以使用 terraform 工作区列表命令:
terraform workspace list
This command will list all the workspaces in your Terraform configuration.此命令将列出 Terraform 配置中的所有工作区。
To list the AWS resources created using a specific Terraform workspace, you can use the terraform state list command:要列出使用特定 Terraform 工作区创建的 AWS 资源,您可以使用 terraform state list 命令:
terraform state list -state=<workspace_name>.tfstate
Replace <workspace_name> with the name of the Terraform workspace you want to inspect.将 <workspace_name> 替换为您要检查的 Terraform 工作空间的名称。 This command will list all the resources that have been created in that workspace.
此命令将列出已在该工作区中创建的所有资源。
Note that the terraform state list
command requires the .tfstate
file of the workspace you want to inspect.请注意,
terraform state list
命令需要您要检查的工作区的.tfstate
文件。 If the workspace was created with a remote backend, you may need to configure the backend first before running this command.如果工作区是使用远程后端创建的,您可能需要在运行此命令之前先配置后端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.