Skip to content

Instantly share code, notes, and snippets.

@jamesdavidson
Created March 27, 2024 10:21
Show Gist options
  • Save jamesdavidson/e805d2ae89a3a2eb629f1d01baad3bce to your computer and use it in GitHub Desktop.
Save jamesdavidson/e805d2ae89a3a2eb629f1d01baad3bce to your computer and use it in GitHub Desktop.
Self signed cert and private key for development and local testing
terraform {
required_providers {
tls = {
version = "4.0.5"
}
local = {
version = "2.5.1"
}
}
}
resource "tls_private_key" "capriv" {
algorithm = "RSA"
}
resource "tls_self_signed_cert" "cacert" {
private_key_pem = tls_private_key.capriv.private_key_pem
subject {
common_name = "example.com"
organization = "ACME Examples, Inc"
}
validity_period_hours = 168 // 1 week
allowed_uses = [
"cert_signing",
]
}
resource "local_sensitive_file" "capriv" {
content = tls_private_key.capriv.private_key_pem
filename = "capriv.pem"
}
resource "local_file" "cacert" {
content = tls_self_signed_cert.cacert.cert_pem
filename = "cacert.pem"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment