0% found this document useful (0 votes)
32 views

3c Terraform TLS Provider

The Terraform TLS provider allows creation of TLS keys, certificates, and certificate requests as part of a Terraform deployment. The document demonstrates configuring the TLS provider and generating a self-signed certificate. It shows adding the TLS provider to terraform.tf, running terraform init to install it, and updating main.tf to generate a private key and save it locally as MyAWSKey.pem.

Uploaded by

Eyad Zaen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

3c Terraform TLS Provider

The Terraform TLS provider allows creation of TLS keys, certificates, and certificate requests as part of a Terraform deployment. The document demonstrates configuring the TLS provider and generating a self-signed certificate. It shows adding the TLS provider to terraform.tf, running terraform init to install it, and updating main.tf to generate a private key and save it locally as MyAWSKey.pem.

Uploaded by

Eyad Zaen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab: Terraform TLS Provider

The Terraform TLS provider provides utilities for working with Transport Layer Security keys and
certificates. It provides resources that allow private keys, certificates and certficate requests to be
created as part of a Terraform deployment.

• Task 1: Check Terraform


• Task 2: Install Terraform TLS Provider
• Task 3: Creates a self-signed certificate with TLS Provider

Task 1: Check Terraform version

Run the following command to check the Terraform version:

terraform -version

You should see:

Terraform v1.0.8

Task 2: Install Terraform TLS Provider

Edit the file titled terraform.tf to add the Terraform TLS provider.

terraform.tf

terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
}
http = {
source = "hashicorp/http"
version = "2.1.0"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
local = {
source = "hashicorp/local"
version = "2.1.0"

1
}
tls = {
source = "hashicorp/tls"
version = "3.1.0"
}
}
}

Install the provider by performing a terraform init

terraform init

This informs Terraform that it will install the TLS provider for working with Transport Layer Security
keys and certificates.

Validate the installation by running a terraform version

terraform version

Terraform v1.0.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.62.0
+ provider registry.terraform.io/hashicorp/http v2.1.0
+ provider registry.terraform.io/hashicorp/local v2.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/hashicorp/tls v3.1.0

Task 3: Creates a self-signed certificate with TLS Provider

Update the main.tf file with the followig configuration blocks for generating a TLS self signed certifi-
cate and saving the private key locally.

resource "tls_private_key" "generated" {


algorithm = "RSA"
}

resource "local_file" "private_key_pem" {


content = tls_private_key.generated.private_key_pem
filename = "MyAWSKey.pem"
}

Note: This example creates a self-signed certificate for a development environment. THIS IS NOT
RECOMMENDED FOR PRODUCTION SERVICES.

Create the Keypair via Terraform

2
terraform apply

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?


Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Validate you now have a self-signed private key inside your current working directory name
MyAWSKey.pem

ls -la

-rwxr-xr-x 1 student student MyAWSKey.pem

cat MyAWSKey.pem

-----BEGIN RSA PRIVATE KEY-----


MIIEowIBAAKCAQEAv7Y/09hkhorQUPEdsmWSej62NoTucPvZCyaKqtKs/UnGM31A
Q2w7yQ2VPuEUP1SPJsk0CgJFRHdLQ/uUFWJAtTTE0iV2sOKL77mMZKZREsmG3wT0
m5Xh3uT8SPhkLFOwgQfPjVdCKFNs8Qip4S6sktWgtw0mV/SioDNYZArNhV+viye0
wa/jXu55H/C1d4HcaALb9+UcruT0M5Kqo1Xjgt6gGDpQjidK0Qsdjyaoz8JKQMbK
fZV3DWC9RJ+Sm94gqt9QbiJgnCVlP8IWEcyMBA6P99RSjNB/geH/H4Jvoeg7W1B1
56/s1vZ4G0XzydlyLY7v5j0vyRumAqq5boCv3QIDAQABAoIBAFv4QoaOuSsSTP2H
rod20t5yV1ewTfNF3snKo5tvli2sxrjMzZeKxOOe8IpJ0DzRhBtHSv/CNxixYhor
Bs97Yy+LMSDfeCFDjX5jtUZTw3EP3PQAnJhHPyR/Fcir4OKjA3njFV7pDYPrAchg
L58nlQKcGY23cT2gzqOr/iuAQz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PRIVATE KEY-----

We will use this private key in a future lab for associating with our server instances and using it for a
means of authentication.

You might also like