Hi, I’m new to Terraform and am trying to figure out how to add encrypted secrets to GitHub Actions. Here’s my resource:
resource “github_actions_secret” “encrypted_my_secret” {
repository = var.secret_repo
secret_name = “SECRET_KEY”
encrypted_value = var.encrypted_secret_value
}
And my variable:
variable “encrypted_secret_value” {
default = “EncryptedMyPassword”
}
The error I get is:
Error: PUT https://api.github.com/repos/-----/-----/actions/secrets/SECRET_KEY: 422 Invalid request.
│
│ EncryptedMyPassword does not match /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.
“SECRET_KEY” exists in my repo as a plaintext secret.
Obviously, I’m getting the error because my PW is not encrypted. So how do I encrypt it? According to this doc, the /crypto/box Go module does the encryption. How do I use this module within TF? Do I add Box as a required provider, add the Box module, then somehow encrypt within my TF file? Or am I supposed to encrypt the string separately in a Go script? Please advise.