tofu-quick-start

Terraform (Tofu) Quick Start

Abstract

Throughout my career there has been endless change and as a result endless learning. I enjoy the challenge. Recently, I decided to refine my Infrastructure as Code (IaC) skills by creating a project with the intent to write a simple how-to mixing Terradata (OpenTofu) with KinD (Kubernetes in Docker) and a deployment of microservice using OpenFaaS Community Edition (CE). The end result is documented at https://fraserswaxway.github.io/tofu-quick-start/ and all the files are at https://github.com/fraserswaxway/tofu-quick-start. Most [somewhat] technical people should be able to use the provided files and see a result in around 30 minutes.

Contents

  1. Environment
  2. Folder and Files
  3. HashiCorp Configuration Language (HCL)
    3.1 Functions
    3.2 Providers
    3.3 Variables
    3.4 Data
    3.5 Resource
  4. Command Line Interface (CLI) - Apply
  5. cURL Validation
  6. Command Line Interface (CLI) - Destroy
  7. Tips

Acknowledgements

1. Environment

2. Folder and Files

Create a working folder (example: tofu-quick-start) with the files and contents as shared at https://github.com/fraserswaxway/tofu-quick-start.

tofu-quick-start
|-- main.tf
|-- output.tf
|-- provider.tf
|-- terraform.tfvars
`-- variables.tf

3. HashiCorp Configuration Language (HCL)

HCL is used to specify (code) OpenTofu (Terraform).

3.1 Functions

Terraform’s built-in functions allow manipulation and transformation of data within configuration.

3.2 Providers

Terraform providers are tools for various platforms such as Amazon Web Services, Azure, Kubernetes, KinD, and Docker.

Providers can be found using search.

The example includes a provider for Kubernetes and other in the file provider.tf.

3.3 Variables

Terraform variables allow customization without changing configuration files.

The example includes a variable for the KinD image tag in the file variables.tf.

3.4 Data

Use Terraform data to retrieve and access information outside of the OpenTofu process.

3.5 Resource

A Terraform resourc is used to define an infrastructure object.

The example includes a resource KinD cluster in the file main.tf.

Note, the use of depends_on to explicitly control object creation order.

4. Command Line Interface (CLI) - Apply

Use the following commands to

Note, the use of -auto-approve avoids a prompt to continue after the plan is displayed.

5. cURL Validation

Use the following command to validate the microservice returns environment variable from the sample function.

curl -X POST http://localhost:8080/function/env -d ''

6. Command Line Interface (CLI) - Destroy

Use the following commands to

Note, again the use of -auto-approve avoids a prompt to continue after the plan is displayed.

7. Tips

Following are some additional tips.

About the Author

Stuart Fraser has a Master of Science in Computer Science from Old Dominion University and is a consulting Principal Architect at Axway.

Acknowledgements

Special thanks to Axway for affording and enabling skills development.