From 5308376a672618461706fc8b10759ef4425e9d48 Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Tue, 4 Jul 2023 21:04:16 +0200 Subject: [PATCH] add terraform deployment example --- deployments/README.md | 4 ++- deployments/terraform/README.md | 41 ++++++++++++++++++++++++++++ deployments/terraform/docker.tf | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 deployments/terraform/README.md create mode 100644 deployments/terraform/docker.tf diff --git a/deployments/README.md b/deployments/README.md index 85697ef1..44323dcf 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -54,7 +54,9 @@ All of the previously deployments, `docker`, `kubernetes` and `openshift` are gr ## 6. Terraform -To be written +Terraform is a tool for infrastructure provisioning to build infrastructure through code, often called Infrastructure as Code. So, Terraform allows you to automate and manage your infrastructure, your platform, and the services that run on that platform. By using Terraform you can deploy your Kerberos Agents remotely at scale. + +> Learn more [about Kerberos Agent with Terraform](https://github.com/kerberos-io/agent/tree/master/deployments/terraform). ## 7. Salt diff --git a/deployments/terraform/README.md b/deployments/terraform/README.md new file mode 100644 index 00000000..25330ed5 --- /dev/null +++ b/deployments/terraform/README.md @@ -0,0 +1,41 @@ +# Deployment with Terraform + +If you are using Terraform as part of your DevOps stack, you might utilise it to deploy your Kerberos Agents. Within this deployment folder we have added an example Terraform file `docker.tf`, which installs the Kerberos Agent `docker` container on a remote system over `SSH`. We might create our own provider in the future, or add additional examples for example `snap`, `kubernetes`, etc. + +For this example we will install Kerberos Agent using `docker` on a remote `linux` machine. Therefore we'll make sure we have the `TelkomIndonesia/linux` provider initialised. + + terraform init + +Once initialised you should see similar output: + + Initializing the backend... + + Initializing provider plugins... + - Reusing previous version of telkomindonesia/linux from the dependency lock file + - Using previously-installed telkomindonesia/linux v0.7.0 + +Go and open the `docker.tf` file and locate the `linux` provider, modify following credentials accordingly. Make sure they match for creating an `SSH` connection. + + provider "linux" { + host = "x.y.z.u" + port = 22 + user = "root" + password = "password" + } + +Apply the `docker.tf` file, to install `docker` and the `kerberos/agent` docker container. + + terraform apply + +Once done you should see following output, and you should be able to reach the remote machine on port `80` or if configured differently the specified port you've defined. + + 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 + + linux_script.install_docker_kerberos_agent: Modifying... [id=a56cf7b0-db66-4f9b-beec-8a4dcef2a0c7] + linux_script.install_docker_kerberos_agent: Modifications complete after 3s [id=a56cf7b0-db66-4f9b-beec-8a4dcef2a0c7] + + Apply complete! Resources: 0 added, 1 changed, 0 destroyed. diff --git a/deployments/terraform/docker.tf b/deployments/terraform/docker.tf new file mode 100644 index 00000000..5a46b72a --- /dev/null +++ b/deployments/terraform/docker.tf @@ -0,0 +1,47 @@ +terraform { + required_providers { + linux = { + source = "TelkomIndonesia/linux" + version = "0.7.0" + } + } +} + +provider "linux" { + host = "x.y.z.u" + port = 22 + user = "root" + password = "password" +} + +locals { + image = "kerberos/agent" + version = "latest" + port = 80 +} + +resource "linux_script" "install_docker" { + lifecycle_commands { + create = "apt update && apt install -y $PACKAGE_NAME" + read = "apt-cache policy $PACKAGE_NAME | grep 'Installed:' | grep -v '(none)' | awk '{ print $2 }' | xargs | tr -d '\n'" + update = "apt update && apt install -y $PACKAGE_NAME" + delete = "apt remove -y $PACKAGE_NAME" + } + environment = { + PACKAGE_NAME = "docker" + } +} + +resource "linux_script" "install_docker_kerberos_agent" { + lifecycle_commands { + create = "docker pull $IMAGE:$VERSION && docker run -d -p $PORT:80 --name agent $IMAGE:$VERSION" + read = "docker inspect agent" + update = "docker pull $IMAGE:$VERSION && docker rm agent --force && docker run -d -p $PORT:80 --name agent $IMAGE:$VERSION" + delete = "docker rm agent --force" + } + environment = { + IMAGE = local.image + VERSION = local.version + PORT = local.port + } +} \ No newline at end of file