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.
Acknowledgements
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
HCL is used to specify (code) OpenTofu (Terraform).
Terraform’s built-in functions allow manipulation and transformation of data within configuration.
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.
Terraform variables allow customization without changing configuration files.
The example includes a variable for the KinD image tag in the file variables.tf.
Use Terraform data to retrieve and access information outside of the OpenTofu process.
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.
Use the following commands to
cd tofu-quick-start
tofu init -upgrade
tofu apply -auto-approve
Note, the use of -auto-approve avoids a prompt to continue after the plan is displayed.
Use the following command to validate the microservice returns environment variable from the sample function.
curl -X POST http://localhost:8080/function/env -d ''
Use the following commands to
tofu destroy -auto-approve
Note, again the use of -auto-approve avoids a prompt to continue after the plan is displayed.
Following are some additional tips.
Login to OpenFaaS CE is required to use most faas-cli commands
faas-cli login -u admin -p $(kubectl -n openfaas get secret basic-auth -o jsonpath=’{.data.basic-auth-password}’ | base64 –decode)
Use the following command to list OpenFaaS CE public images
faas-cli store list
Deploy additional OpenFaaS CE public images using
faas-cli store deploy
Example: faas-cli store deploy nslookup
Function deployments to OpenFaaS may take several seconds (consider waiting 30 seconds before performing a validation test)
Validate OpenFaaS functions using
curl -X POST http://
Example: curl -X POST http://localhost:8080/function/nslookup -d ‘amazon.com’
Stuart Fraser has a Master of Science in Computer Science from Old Dominion University and is a consulting Principal Architect at Axway.
Special thanks to Axway for affording and enabling skills development.