faun.pub
Open in
urlscan Pro
162.159.153.4
Public Scan
Submitted URL: https://view.hashicorp.com/ODQ1LVpMRi0xOTEAAAGLFHMouJsZSI2SdUdAbNmXQzVVL9Gb-AwHcO-TwI1mlp-CWTNrddBjZL6-iQlGfe5jFOKJyWk=
Effective URL: https://faun.pub/demystify-terraform-provisioners-f75e738a824?gi=77699f39119f&mkt_tok=ODQ1LVpMRi0xOTEAAAGLFHMouJM...
Submission: On April 12 via api from US — Scanned from DE
Effective URL: https://faun.pub/demystify-terraform-provisioners-f75e738a824?gi=77699f39119f&mkt_tok=ODQ1LVpMRi0xOTEAAAGLFHMouJM...
Submission: On April 12 via api from US — Scanned from DE
Form analysis
0 forms found in the DOMText Content
Open in app Sign up Sign In Write Sign up Sign In Published in FAUN Publication Ink Insight Follow Mar 6 · 5 min read · Listen Save DEMYSTIFY TERRAFORM PROVISIONERS A TECHNICAL DEEP DIVE INTO LOCAL-EXEC, REMOTE-EXEC, AND FILE Photo by Neora Aylon on Unsplash Terraform is a popular infrastructure as code (IaC) tool that enables you to automate infrastructure deployments, management, and changes. One of the key features of Terraform is its ability to run scripts on remote infrastructure using provisioners. There are various types of provisioners available in Terraform, including local-exec, remote-exec, and file, each with its own specific use case. > In this blog, we will take a deep dive into the different Terraform > provisioners, and provide step-by-step examples of how to use each one: LOCAL-EXEC PROVISIONER The local-exec provisioner is used to run a command on the local machine running Terraform. This provisioner is useful when you need to execute a command locally as part of the Terraform deployment process, such as updating a local configuration file or installing a package. Pros: * Simple to use as it runs shell commands directly on the local machine. * Great for quick and simple tasks. Cons: * Only works when Terraform is run on the same machine where the target resource exists. * Can be prone to security issues if not careful with the commands that are run. Here’s an example of how to use the local-exec provisioner in Terraform: resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" provisioner "local-exec" { command = "echo ${self.private_ip} > ip_address.txt" } } > In this example, we’re using the local-exec provisioner to run the echo > command and store the private IP address of the EC2 instance in a text file > called ip_address.txt. This can be useful when you need to store information > about your infrastructure for later use. BASIC | HOW TO DEBUG TERRAFORM DEPLOYMENT ISSUES: TIPS AND TRICKS DEBUGGING TERRAFORM DEPLOYMENT ISSUES CAN BE A TIME-CONSUMING AND FRUSTRATING PROCESS. HOWEVER, WITH THE RIGHT… medium.com REMOTE-EXEC PROVISIONER The remote-exec provisioner is used to run a command on a remote machine as part of the Terraform deployment process. This provisioner is useful when you need to execute a command on a remote machine, such as installing a package or updating a configuration file. Pros: * Can run commands on remote machines, making it useful for deploying to multiple machines. * Can be used to automate tasks on remote machines, even if Terraform is not running on that machine. Cons: * Can be more complex to set up and use, especially when dealing with remote machines that have strict security requirements. * Can be prone to security issues if not careful with the commands that are run. Here’s an example of how to use the remote-exec provisioner in Terraform: resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" provisioner "remote-exec" { inline = [ "sudo apt-get update", "sudo apt-get install -y apache2" ] } } > In this example, we’re using the remote-exec provisioner to install the Apache > web server on the EC2 instance. The inline argument is used to specify the > commands to be run on the remote machine. Photo by Arnold Francisca on Unsplash FILE PROVISIONER The file provisioner is used to upload files to a remote machine as part of the Terraform deployment process. This provisioner is useful when you need to transfer files to a remote machine, such as configuration files or scripts. Pros: * Simple to use for transferring files to remote machines. * Great for transferring static content to web servers or for transferring configuration files to machines. Cons: * Only transfers files and does not execute any commands. * Can be limited in terms of the tasks it can perform. Here’s an example of how to use the file provisioner in Terraform: resource "aws_instance" "web_server" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" provisioner "file" { source = "index.html" destination = "/var/www/html/index.html" } } > In this example, we’re using the file provisioner to upload a file called > index.html to the EC2 instance and place it in the /var/www/html directory. > This can be useful when you need to transfer static content to a web server or > when you need to transfer configuration files to a machine. After reviewing numerous implementations, here is how we can determine which provisioner to choose. The following factors should be taken into consideration: * Is the task simple enough to be executed locally or does it require access to a remote machine? * Does the task require executing commands or just transferring files * What are the security requirements for the task? > If the task is simple enough to be executed locally, use the local-exec > provisioner. If the task requires access to a remote machine, use the > remote-exec provisioner. If the task only requires transferring files, use the > file provisioner. It’s important to keep in mind the security requirements for the task and make sure that the chosen provisioner can meet those requirements. It’s also important to consider the complexity of the task and choose the simplest solution that meets your needs. > In conclusion, Terraform provisioners provide a powerful way to automate tasks > as part of your infrastructure deployment process. By understanding the pros > and cons of each provisioner, you can choose the right one for your specific > use case and ensure that your infrastructure is deployed, configured, and > managed in a consistent and automated way. Thanks for reading! I’d appreciate your support and engagement in my stories. :) Don’t miss a beat — subscribe to my Medium newsletter to get my latest articles and content before anyone else. And if you enjoy what you’re reading, be sure to follow me for even more great content! And, as always, thank you for taking the time to read and engage with my content — your support means the world to me! A COMPREHENSIVE GUIDE TO BLUE-GREEN, CANARY, AND ROLLING DEPLOYMENTS DEPLOYMENT STRATEGIES ARE AN IMPORTANT ASPECT OF DEVOPS, AS THEY DETERMINE HOW NEW SOFTWARE RELEASES ARE DEPLOYED TO… medium.com 👋 IF YOU FIND THIS HELPFUL, PLEASE CLICK THE CLAP 👏 BUTTON BELOW A FEW TIMES TO SHOW YOUR SUPPORT FOR THE AUTHOR 👇 🚀JOIN FAUN DEVELOPER COMMUNITY & GET SIMILAR STORIES IN YOUR INBOX EACH WEEK DevOps Terraform Infrastructure As Code Kubernetes Cloud 72 72 72 SIGN UP FOR FAUN BY FAUN PUBLICATION Medium’s largest and most followed independent DevOps publication. Join thousands of developers and DevOps enthusiasts. Take a look. By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices. Get this newsletter MORE FROM FAUN PUBLICATION Follow We help developers learn and grow by keeping them up with what matters. 👉 www.faun.dev Harsh Manvar ·Feb 22 KUBERNETES INGRESS VS GATEWAY API Understanding the Differences between Kubernetes Ingress and Gateway API for Effective Traffic Management Overview One of the most widely used solutions for managing containers and orchestrating microservices is Kubernetes. Yet, Kubernetes has two choices for controlling inbound traffic to these microservices: Ingress and Gateway API. This post will contrast and compare… Kubernetes 5 min read Kubernetes 5 min read -------------------------------------------------------------------------------- Share your ideas with millions of readers. Write on Medium -------------------------------------------------------------------------------- Paul Brissaud ·Nov 4, 2022 WHY YOU SHOULDN’T USE KUBERNETES Kubernetes has become a standard in modern IT in less than a decade. All major companies, whether they are technological or not, use it to host their entire information system. And that’s normal because this technology has many features like auto-remediation or horizontal and vertical scaling to ensure that infrastructure… Kubernetes 6 min read Kubernetes 6 min read -------------------------------------------------------------------------------- Haimo Zhang ·Jan 26 Member-only USING CHATGPT TO CREATE AWS CLOUDFORMATION & TERRAFORM TEMPLATES ChatGPT was launched as a prototype in November 2022 by OpenAI, and quickly got the world attentions for its detailed responses and articulate answers across many domains. CloudFormation and Terraform are both infrastructure-as-code (IaC) tools. CloudFormation is developed by AWS and only manages AWS resources. Terraform is developed by HashiCorp… ChatGPT 5 min read ChatGPT 5 min read -------------------------------------------------------------------------------- Nwachukwu Chibuike ·Mar 3 BACKENDS FOR FRONTENDS — MY TAKE What do you get when you have a lot of Microservices to fetch data from before displaying a result — Multiple network calls; add the need to display results based on the requesting client and it becomes a dilemma. Solution? Backends For Frontends(BFF) In this article, we would get to… Microservices 5 min read Microservices 5 min read -------------------------------------------------------------------------------- Pavan Belagatti ·Sep 8, 2022 DOCKERFILE BEST PRACTICES FOR DEVELOPERS Docker Best Practices in 2022. This article will explain more about Docker, as well as how to write the optimal Docker file to build and deploy your applications Software development has evolved and changed over the years for good reasons. Organizations, big or small, have discovered the value of modern… Docker 7 min read Docker 7 min read -------------------------------------------------------------------------------- Read more from FAUN Publication AboutHelpTermsPrivacy -------------------------------------------------------------------------------- GET THE MEDIUM APP INK INSIGHT 499 Followers Discover the intersection of DevOps, InfoSec, mindfulness, and self-improvement with Ink Insight. Follow for engaging content and valuable insights! ✍︎ Follow MORE FROM MEDIUM Mohamed Dhaoui HOW TO KEEP YOUR TERRAFORM CODE CLEAN AND ROBUST (PART1)? Manu Magalhães GENERATING DYNAMIC JSON IN TERRAFORM The PyCoach in Artificial Corner YOU’RE USING CHATGPT WRONG! HERE’S HOW TO BE AHEAD OF 99% OF CHATGPT USERS Oleksandr Rozdolskyi A STEP-BY-STEP GUIDE FOR YOUR FIRST 90 DAYS AS A SENIOR DEVOPS ENGINEER Help Status Writers Blog Careers Privacy Terms About Text to speech To make Medium work, we log user data. By using Medium, you agree to our Privacy Policy, including cookie policy.