如何从 terraform 状态打印出敏感值?

Ale*_*nov 2 terraform

目标:我想打印出 的敏感值foo_resource.name.sensitive_field

\n

最初我尝试创建一个输出

\n
output "password" {\n  value       = foo_resource.name.sensitive_field\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我得到了

\n
 Error: Output refers to sensitive values\n\xe2\x94\x82 \n\xe2\x94\x82   on main.tf line 186:\n\xe2\x94\x82  186: output "password" {\n\xe2\x94\x82 \n\xe2\x94\x82 To reduce the risk of accidentally exporting sensitive data that was intended to be only internal, Terraform requires that any root module output containing sensitive data be\n\xe2\x94\x82 explicitly marked as sensitive, to confirm your intent.\n\xe2\x94\x82 \n\xe2\x94\x82 If you do intend to export this data, annotate the output value as sensitive by adding the following argument:\n\xe2\x94\x82     sensitive = true\n\xe2\x95\xb5\n
Run Code Online (Sandbox Code Playgroud)\n

所以我添加sensitive = true了:

\n
output "password" {\n  value       = foo_resource.name.sensitive_field\n  sensitive = true\n}\n
Run Code Online (Sandbox Code Playgroud)\n

然后当我再次运行它时,我得到:

\n
$ terraform output\npassword = <sensitive>\n
Run Code Online (Sandbox Code Playgroud)\n

Ale*_*nov 9

terraform output -raw password
Run Code Online (Sandbox Code Playgroud)

就可以了。

有关更多详细信息,请参阅文档

Note: When using the -json or -raw command-line flag, any sensitive values in Terraform state will be displayed in plain text. For more information, see Sensitive Data in State.
Run Code Online (Sandbox Code Playgroud)

  • 你甚至不需要`-raw`。您只需指定单个值名称:“terraform 输出密码” (8认同)