terraform-provider-null: Allow defining triggers that are sensitive information
Terraform Version
Terraform v0.12.20
- provider.null v2.1.2
Affected Resource(s)
- null_resource
Terraform Configuration Files
variable "mysecret" {
type = string
}
resource null_resource example {
triggers = {
secret = var.mysecret
}
provisioner "local-exec" {
command = "echo Create"
environment = {
SECRET = self.triggers.mysecret
}
}
provisioner "local-exec" {
command = "echo Destroy"
environment = {
SECRET = self.triggers.mysecret
}
}
}
Debug Output
❯ terraform apply
var.mysecret
Enter a value: supersecret
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# null_resource.example will be created
+ resource "null_resource" "example" {
+ id = (known after apply)
+ triggers = {
+ "secret" = "supersecret"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions in workspace "play"?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: no
Apply cancelled.
Expected Behavior
A way to provide sensitive values as triggers, so that the plan does only print (sensitive) and not the actual value of a sensitive trigger.
Actual Behavior
No way to define sensitive triggers.
Steps to Reproduce
terraform apply
Important Factoids
The null_resource should also take a sensitive_triggers map that is obfuscated in the plan output.
Other providers, like the local provider use a similar approach: https://www.terraform.io/docs/providers/local/r/file.html
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 23
- Comments: 20
Commits related to this issue
- Add "sensitive" resource and data source These are functionally identical, but masks the inputs/outputs. Closes https://github.com/hashicorp/terraform-provider-null/issues/38 — committed to grnhse/terraform-provider-null by zhimsel 4 years ago
- Add "sensitive" resource and data source These are functionally identical, but masks the inputs/outputs. Closes https://github.com/hashicorp/terraform-provider-null/issues/38 — committed to grnhse/terraform-provider-null by zhimsel 4 years ago
I’ve been using
sha1in triggers to work around this issue.Right now this behavior is blocking our ability to migrate to terraform 0.13 with the error:
Since we use some secrets to fill in the information in our connection{} block, it is by nature sensitive. Putting the values in the triggers allows us to upgrade but then dumps private keys into our diffs 😕.
What I would like to see happen is something like this:
FYI I opened PR #48 to implement this.
If anyone is interested, can you please give it a spin and report whether it works for you?
Build instructions
You need Go 1.15 installed to build the provider. It’s also possible to use Docker if you don’t want to install Go.
With Go 1.15 installed
The provider can then be found in
$GOPATH/bin.With Docker installed
Linux
First spin up the Go 1.15 container:
Then within that container, do the following:
You can then exit the container and the plugin will be in you current working directory.
macOS
First spin up the Go 1.15 container:
Then within that container, do the following:
You can then exit the container and the plugin will be in you current working directory.
Windows
First spin up the Go 1.15 container from a PowerShell terminal:
Then within that container, do the following:
You can then exit the container and the plugin will be in you current working directory.
Install instructions
Linux
macOS
Windows
Usage instructions
Upgrade your project to use the custom version of the plugin:
@tmatilai Marking variables as sensitive was not a terraform feature when the ticket was opened. It got introduced with 0.14. But yes, it seems to solve the issue. Another alternative is the
sensitivefunction (which came with terraform 0.15): https://www.terraform.io/language/functions/sensitiveChecking with the following code:
The cli output of a plan looks like this:
Given that both of the above solve the issue in a straightforward way, I’m gonna close the ticket as it can be solved with a terraform-native feature without any modification necessary to the provider anymore.
Just checking in, did this go anywhere? Seems to have died 😕
Hi @reegnz, I should have included more context.
Unless I’m misunderstanding the use of
sha1()in a terraform context, that doesn’t solve the problem for our use case which is due to the removal of the ability to use variables inwhen = destroy.We have destroy actions that require variables/files for cleanup actions on services that terraform doesn’t interact with natively. Now variables aren’t allowed in destroy the use of
self.triggers.*is the only way to pass values into the local-exec.In these instances we need the actual value, not to know it was different.