<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sameed Uddin on Medium]]></title>
        <description><![CDATA[Stories by Sameed Uddin on Medium]]></description>
        <link>https://medium.com/@msameeduddin?source=rss-80f402b00930------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9lBNvAWUEINwuWAJAxqpXQ.jpeg</url>
            <title>Stories by Sameed Uddin on Medium</title>
            <link>https://medium.com/@msameeduddin?source=rss-80f402b00930------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:53:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@msameeduddin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unlocking the Power of Amazon Quick Developer Tool: Boosting Efficiency and Innovation]]></title>
            <link>https://msameeduddin.medium.com/unlocking-the-power-of-amazon-quick-developer-tool-boosting-efficiency-and-innovation-3b1f0b76b3e9?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b1f0b76b3e9</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[amazon-q]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Thu, 01 Aug 2024 14:41:06 GMT</pubDate>
            <atom:updated>2024-08-01T14:41:06.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmKzH_5n7gYhF9GLJie8yg.jpeg" /></figure><p>As a software developer, you’re constantly looking for ways to optimize your workflow, reduce errors, and increase productivity. That’s where Amazon Quick Developer Tool comes in — a powerful tool that enables developers to create, test, and deploy applications with unprecedented speed and efficiency.</p><p>In this blog post, we’ll explore the benefits of using Amazon Quick Developer Tool, along with some real-world scenarios to illustrate its potential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPeUvoVCgHprX_PYRr-nxg.png" /></figure><p><strong>What is Amazon Quick Developer Tool?</strong></p><p>Amazon Quick Developer Tool is an integrated development environment (IDE) that provides a comprehensive set of features for building, testing, and deploying cloud-based applications. With Quick Developer Tool, developers can:</p><ul><li>Create, test, and deploy applications with ease</li><li>Use a visual interface to design and develop applications</li><li>Integrate with popular programming languages such as Java, Python, and Node.js</li><li>Leverage Amazon Web Services (AWS) services such as Lambda, S3, and DynamoDB</li></ul><p><strong>Benefits of Using Amazon Quick Developer Tool</strong></p><ol><li><strong>Increased Productivity</strong>: With Quick Developer Tool, developers can create and deploy applications up to 5x faster than traditional development methods.</li><li><strong>Improved Efficiency</strong>: The tool’s visual interface and integrated AWS services enable developers to focus on the application logic, rather than worrying about infrastructure and deployment details.</li><li><strong>Enhanced Collaboration</strong>: Quick Developer Tool allows multiple developers to work together in real-time, using a shared IDE environment.</li><li><strong>Reduced Errors</strong>: The tool’s automated testing and debugging features help catch errors early and prevent costly mistakes.</li></ol><p><strong>Real-World Scenario: Building a Serverless Web Application</strong></p><p>Let’s say you’re building a serverless web application that uses AWS Lambda to process user requests. With Quick Developer Tool, you can:</p><ul><li>Design the application architecture using the visual interface</li><li>Write code in your preferred programming language (e.g., JavaScript)</li><li>Test and debug the application using integrated testing features</li><li>Deploy the application to AWS Lambda with a single click</li></ul><p>Here’s an example code snippet:</p><pre>// Define the Lambda function handler<br>exports.handler = async (event) =&gt; {<br>  // Process user request<br>  const response = await processRequest(event);<br>  return { statusCode: 200, body: JSON.stringify(response) };<br>};<br><br>// Test the Lambda function using Quick Developer Tool<br>describe(&#39;Lambda Function Handler&#39;, () =&gt; {<br>  it(&#39;should process user requests correctly&#39;, async () =&gt; {<br>    const event = { /* Define test event */ };<br>    const response = await handler(event);<br>    expect(response.statusCode).toBe(200);<br>  });<br>});</pre><p><strong>Conclusion</strong></p><p>Amazon Quick Developer Tool is a game-changing tool for software developers, offering unprecedented efficiency, innovation, and productivity benefits. With its visual interface, integrated AWS services, and automated testing features, Quick Developer Tool enables developers to create, test, and deploy applications with ease.</p><p>Whether you’re building a serverless web application or a complex enterprise system, Quick Developer Tool is the perfect tool for the job. Try it out today and experience the power of Amazon Quick Developer Tool for yourself!</p><p>Also make sure to follow, like and subscribe for more content on medium.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b1f0b76b3e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Amazon Inspector with Terraform in an AWS Control Tower Landing Zone]]></title>
            <link>https://msameeduddin.medium.com/configuring-amazon-inspector-with-terraform-in-an-aws-control-tower-landing-zone-6ba205becb94?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ba205becb94</guid>
            <category><![CDATA[aws-inspector]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[aws-organizations]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 21:54:36 GMT</pubDate>
            <atom:updated>2024-07-27T21:54:36.951Z</atom:updated>
            <content:encoded><![CDATA[<p>First of all , sorry i couldn&#39;t post for more than a year due to immigration etc and thank you all for still staying , following &amp; giving me likes for all my older posts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*9Q1K34y-DdXPny2HbOKaNA.jpeg" /></figure><h3>Introduction:</h3><p>As organizations increasingly adopt cloud-first strategies, ensuring the security and compliance of their AWS workloads has become a top priority. One key service in this effort is Amazon Inspector, a vulnerability management tool that continuously scans EC2 instances, container images in ECR, and Lambda functions for software vulnerabilities and unintended network exposure.</p><p>In this post, we’ll explore how to configure Amazon Inspector using Terraform within an AWS Control Tower landing zone. We’ll cover the benefits of using Inspector in a multi-account environment, such as those established through AWS Organizations, and demonstrate how to leverage the delegated administrator feature to manage multiple accounts from a single central location.</p><p><strong>Why Configure Amazon Inspector with Terraform?</strong></p><p>Using Terraform to configure Amazon Inspector offers several advantages, including:</p><ul><li><strong>Consistency</strong>: Apply Inspector configurations across multiple accounts and environments with ease.</li><li><strong>Reusability</strong>: Leverage existing Terraform modules to speed up the configuration process.</li><li><strong>Version control</strong>: Track changes to your Inspector configurations over time using version control.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*VUPU25k3WDdWzjQ1YiE5vA.jpeg" /><figcaption>Source: <a href="https://blog.avangards.io/how-to-manage-amazon-inspector-in-aws-organizations-using-terraform">https://blog.avangards.io/how-to-manage-amazon-inspector-in-aws-organizations-using-terraform</a></figcaption></figure><p><strong>Identifying Relevant Accounts in the Landing Zone</strong></p><ul><li>Within our Control Tower landing zone, we have two key accounts that are relevant for our use case:</li></ul><ol><li><strong>Management Account</strong>: This is the organization’s management account where AWS Organizations is configured. If you’re new to managing multiple accounts with Organizations, refer to <a href="https://docs.aws.amazon.com/inspector/latest/user/what-is-inspector.html">Amazon Inspector’s</a> on Managing Multiple Accounts with Organizations.</li><li><strong>Audit Account</strong>: In a typical Control Tower landing zone, security and compliance services are centralized in an audit account.</li></ol><p><strong>Setting Up a Delegated Administrator Account</strong></p><p>The first step is to set up a delegated administrator account using Terraform. This will allow us to configure Inspector settings for all member accounts in your organization. We’ll use the aws_inspector2_delegated_admin_account resource to create this account and make it the delegated admin.</p><p>Here’s an example code snippet:</p><pre># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-west-2&quot;<br>}</pre><pre># Create a delegated administrator account for Inspector<br>resource &quot;aws_inspector2_delegated_admin_account&quot; &quot;example&quot; {<br>  name         = &quot;Example Delegated Admin Account&quot;<br>  description = &quot;Delegated admin account for Amazon Inspector&quot;<br>}</pre><p><strong>Enabling Inspector for New Member Accounts</strong></p><p>Now that we have our delegated administrator account set up, let’s talk about enabling Inspector for new member accounts. With auto-enablement, new member accounts will automatically get configured with the desired scan types. We’ll use the aws_inspector2_member_association resource to associate these new members with our delegated admin.</p><p>Here’s an example code snippet:</p><pre># Associate new member accounts with the delegated administrator account<br>resource &quot;aws_inspector2_member_association&quot; &quot;example&quot; {<br>  count       = var.new_member_accounts<br>  delegated_admin_account_id = aws_inspector2_delegated_admin_account.example.id<br>}</pre><p><strong>Disabling Inspector for Existing Member Accounts</strong></p><p>But what about existing member accounts? Well, we can use Terraform to dynamically configure these accounts with the desired scan types as well! We’ll create an aws_inspector2_enabler resource that will enable Inspector on all existing member accounts.</p><p>Here’s an example code snippet:</p><pre># Enable Inspector for existing member accounts<br>resource &quot;aws_inspector2_enabler&quot; &quot;example&quot; {<br>  count       = var.existing_member_accounts<br>  delegated_admin_account_id = aws_inspector2_delegated_admin_account.example.id<br>}</pre><p><strong>The Power of Terraform</strong></p><p>Terraform is a powerful tool that allows us to manage our AWS resources in a declarative way. With Terraform, we can define our infrastructure as code and use the terraform apply command to create it. When we need to update or delete resources, we simply run terraform destroy.</p><p><strong>Caveats</strong></p><p>When using Terraform to manage Inspector resources, keep in mind that deactivating Inspector on member accounts requires a bit more effort than just running terraform destroy. You&#39;ll need to manually deactivate the account in each applied region. Alternatively, you can first run terraform apply so that the resource instances are created, then run terraform destroy to properly clean up.</p><p>That’s it! With this guide, you should now be able to manage Amazon Inspector in your AWS Organization using Terraform. Happy infra-ing!</p><p><em>Note: The above code snippets are examples and may need to be modified to fit your specific use case. Make sure to test the code in a non-production environment before applying it to your production resources.</em></p><p>“Thanks for reading! Don’t forget to hit that follow button, give this post a like, and subscribe to my Medium account for more in-depth guides and tutorials on cloud services, DevOps tools, and infrastructure as code — I’ll see you in the next one!”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ba205becb94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating GKE Cluster Using Terraform]]></title>
            <link>https://faun.pub/creating-gke-cluster-using-terraform-68f421d1212f?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/68f421d1212f</guid>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[gke]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Sun, 01 May 2022 20:32:49 GMT</pubDate>
            <atom:updated>2022-05-16T13:05:11.424Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*QKtvjH2UJ_ixKITk.png" /><figcaption>Image by Nick Joyce</figcaption></figure><p>Lets first figure out what is kubernetes and how it will help us with containers</p><p><strong>What is Kubernetes?</strong></p><p>With the widespread adoption of <a href="https://cloud.google.com/containers">containers</a> among organizations, Kubernetes, the container-centric management software, has become the de facto standard to deploy and operate containerized applications. Google Cloud is the birthplace of Kubernetes — originally developed at Google and released as open source in 2014. Kubernetes builds on 15 years of running Google’s containerized workloads and the valuable contributions from the open source community. Inspired by Google’s internal cluster management system, <a href="https://research.google.com/pubs/pub43438.html">Borg</a>, Kubernetes makes everything associated with deploying and managing your application easier. Providing automated container orchestration, Kubernetes improves your reliability and reduces the time and resources attributed to daily operations.</p><p><strong>What are the Benefits of k8s?</strong></p><p><strong>Automated operations</strong></p><p>Kubernetes has built-in commands to handle a lot of the heavy lifting that goes into application management, allowing you to automate day-to-day operations. You can make sure applications are always running the way you intended them to run.</p><p><strong>Infrastructure abstraction</strong></p><p>When you install Kubernetes, it handles the compute, networking, and storage on behalf of your workloads. This allows developers to focus on applications and not worry about the underlying environment.</p><p><strong>Service health monitoring</strong></p><p>Kubernetes continuously runs health checks against your services, restarting containers that fail, or have stalled, and only making available services to users when it has confirmed they are running.</p><p><a href="https://cloud.google.com/kubernetes-engine"><strong>Google Kubernetes Engine</strong></a> (GKE) is an easy to use cloud based Kubernetes (Managed) service for running containerized applications. GKE can help you implement a successful Kubernetes strategy for your applications in the cloud.</p><p><strong>Now we have to figure out What is IaC? &amp; Why use Terraform?</strong></p><p>Infrastructure as code (IaC) literally means is to manage your IT infrastructure using configuration files which can be customized, manage very big chunk of resources very easily in different environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*41RF1VQ24Yza281j.png" /><figcaption>Terraform Logo</figcaption></figure><p><a href="https://www.terraform.io/intro/index.html">HashiCorp Terraform</a> is an infrastructure as code tool that lets you define infrastructure resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to safely and efficiently provision and manage your infrastructure throughout its lifecycle.</p><p>It generates an execution plan detailing what it needs to do in order to reach reach the desired state, and then executes the code to build the described infrastructure. Once the configuration changes, Terraform can determine whats changed inside the code and create incremental execution plans which can be applied by you.</p><p>Step 1:- Lets install Terraform using the code below.</p><p><strong>For Linux :-</strong></p><pre><strong>Ubuntu/Debian installation</strong><br>curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -</pre><pre>sudo apt-add-repository &quot;deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main&quot;</pre><pre>sudo apt-get update &amp;&amp; sudo apt-get install terraform</pre><pre><strong>RHEL/CentOS Installation</strong></pre><pre>sudo yum install -y yum-utils</pre><pre>sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo</pre><pre>sudo yum -y install terraform</pre><p>For Windows:-</p><p>You will need Administrator Powershell Access first to install chocolatey</p><pre>Copy this command below &amp; paste in Powershell window &amp; Enter:</pre><pre>Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(&#39;<a href="https://community.chocolatey.org/install.ps1&#39;">https://community.chocolatey.org/install.ps1&#39;</a>))</pre><ul><li>Wait a few seconds for the command to complete.</li></ul><pre>Then use this command to install terraform on windows:</pre><pre># choco install terraform<br>Once it done , make sure its installed using:<br># terraform -version</pre><p><a href="https://learn.hashicorp.com/tutorials/terraform/install-cli">Install Terraform | Terraform | HashiCorp Developer</a></p><p><strong><em>Step 2 :- Lets setup GCP</em></strong></p><p>First create a project and activate the billing on it. (without it you can do anything) You will get 300$ as a free credits when you create new account with GCP (unless you can upgrade it to paid account).</p><p>Then we can install and configure the Google Cloud SDK and the Kubernetes command line tool(kubectl). This SDK provides helps you to interact with GCP REST API’s, this will allow us to create, customize &amp; manage GCP resources from command-line interface.</p><p>Lets Run the following commands to install and initialize it:</p><p>For Linux:-</p><pre># sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo &lt;&lt; EOM<br>[google-cloud-cli]<br>name=Google Cloud CLI<br>baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64<br>enabled=1<br>gpgcheck=1<br>repo_gpgcheck=0<br>gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg<br>       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg<br>EOM</pre><pre># sudo yum install google-cloud-cli</pre><p>For reference installation links:</p><ul><li><a href="https://cloud.google.com/sdk/docs/install-sdk">Quickstart: Install the Google Cloud CLI | Google Cloud CLI Documentation</a></li><li><a href="https://community.chocolatey.org/packages/gcloudsdk">Google Cloud SDK (Install) 0.0.0.20220203</a></li></ul><pre><strong><em>If you are using Windows:</em></strong><br># choco install gcloudsdk</pre><p>Step 3: We also need kubectl installed on our workstation to access the GKE , Follow the link for installation</p><p><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/">Install and Set Up kubectl on Linux</a></p><pre><strong><em>Once the installations are done its time to initialize &amp; setup gcloud sdk:</em></strong></pre><pre># gcloudsdk init<br>the bowser will up &amp; you need to enter credentials &amp; link with it</pre><p><strong>Step 4:- By Default, most of the services are disabled</strong></p><p><strong>So Now you to enable list of API’s so it can help you use GCP services:</strong></p><p>Compute Engine API &amp; Kubernetes Engine API</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5b6ee55d3b88b1fbc0a1952f2feea9a/href">https://medium.com/media/c5b6ee55d3b88b1fbc0a1952f2feea9a/href</a></iframe><p><strong>Step 5:- Its time to create a Service account</strong></p><pre># gcloud iam service-accounts create terraform-gke</pre><p>(You can use custom name but im going with terraform-gke service account)</p><p><strong>Step 6:- </strong>In order to execute this module you must have a Service Account with the following project roles:</p><ul><li>roles/compute.viewer</li><li>roles/compute.securityAdmin (only required if add_cluster_firewall_rules is set to true)</li><li>roles/container.clusterAdmin</li><li>roles/container.developer</li><li>roles/iam.serviceAccountAdmin</li><li>roles/iam.serviceAccountUser</li><li>roles/resourcemanager.projectIamAdmin (only required if service_account is set to create)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/637c289f79e653f72de752fcba3f1fad/href">https://medium.com/media/637c289f79e653f72de752fcba3f1fad/href</a></iframe><p>Note: make sure to enter &lt;service account name&gt; &amp;&lt;project-name&gt; as your own twice like mine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZB0qBspaYCXbY-g9-q7cTQ.png" /></figure><p><strong>Step 7 :- Finally create a JSON key file from the Service Account </strong>Terraform will use it to authenticate (on-behalf) as the service account on the Google Cloud API using the following command. ( or just go to service accounts &amp; create key there as it will automatically download JSON file)</p><p><a href="https://console.cloud.google.com/iam-admin/serviceaccounts">Google Cloud Platform</a></p><pre># gcloud iam service-accounts keys create terraform-gke-keyfile.json --iam-account=&lt;service-account-name&gt;@&lt;project-name&gt;.iam.gserviceaccount.com</pre><p>Check the GCP Console, review the service account, then go to manage keys &amp; download the JSON file/ key we have created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C9Vjwfyg-jWEdcrkOcNGNw.png" /></figure><p><strong>STEP 8:- </strong>Creating Terraform state in Google Cloud Storage</p><p>By default, Terraform stores the current state of our infrastructure in a local state file.We could commit it with our infrastructure code, But according to Best Practices in order to share a Terraform state when working with different teams is to store it in remote storage. In this case, as we already using GCP why not configure Terraform to store the state in a Google Cloud Storage (GCS)Bucket.</p><p>You can create a bucket from <a href="https://console.cloud.google.com/storage/create-bucket"><strong>Google Cloud Console</strong></a> , or we can use the Google Cloud SDK (installed previously) using:</p><pre># gsutil mb -p &lt;project-name&gt; -c regional -l &lt;location&gt; gs://&lt;bucket-name&gt;/</pre><pre><strong>This is what i did:</strong><br>gsutil mb -p annular-beacon-336307  -c regional -l us-east1  gs://gke-terraformlabs/<br>Creating gs://gke-terraformlabs/...</pre><pre><strong>Once the Bucket is created make sure to enable versioning or state recovery in the case of accidental deletion or errors.</strong></pre><pre>$ gsutil versioning set on gs://&lt;bucket-name&gt;/</pre><p><a href="https://cloud.google.com/storage/docs/creating-buckets?authuser=3">Create storage buckets | Cloud Storage | Google Cloud</a></p><p><strong>We also need to enable read / write permissions on this bucket for our service account using command or through gcp storage in bucket permissions:</strong></p><pre># gsutil iam ch serviceAccount:&lt;service-account-name&gt;@&lt;project-name&gt;.iam.gserviceaccount.com:legacyBucketWriter gs://&lt;bucket-name&gt;/</pre><pre>This is what i did:<br>gsutil iam ch serviceAccount:<a href="/service/mailto:terraform-gke@annular-beacon-336307.iam.gserviceaccount.com">terraform-gke@annular-beacon-336307.iam.gserviceaccount.com</a>:legacyBucketWriter gs://gke-terraformlabs/</pre><p><strong>Step 9:- </strong>Lets configure Terraform to use this bucket to store its state file. Create terraform.tffile &amp; make sure the service account key file is also in the same directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/332ea01cd34e57688e59275a1377f488/href">https://medium.com/media/332ea01cd34e57688e59275a1377f488/href</a></iframe><p>Once you created gcp-terraform-backend.tf,Initialize Terraform plugins inside that directory using # terraform init</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*4013kR0tbzedWLwjr29QkA.png" /><figcaption>This is what i did</figcaption></figure><p><strong>Step 10:- Creating GKE Cluster using Terraform Code</strong></p><p>.terraform/ is a directory created &amp; managed by Terraform, This is where it external modules and plugins are stored for reference. In order to create the GKE cluster with Terraform, we need GCP Terraform provider and a GKE community module. A module is a package of Terraform code that combines different resources to create something more complex. In our case, we will use a single module that will create for us many various resources such as a Google Container cluster, node pools, and a cluster service account.</p><p>To configure terraform to communicate with the Google Cloud API and to create GCP resources, create a providers.tf file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbad49fd774ab7afc918ab22c489cc72/href">https://medium.com/media/fbad49fd774ab7afc918ab22c489cc72/href</a></iframe><p><strong>Step 11:- Creating file to setup GKE Cluster using this code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4710a167afc604745f911a8fb61c36a/href">https://medium.com/media/b4710a167afc604745f911a8fb61c36a/href</a></iframe><p>Make sure to refer the module mentioned earlier &amp; provide it with variables which will automatically pickedup by terraform as long as .tf files are inside parent folder(which we will refer in different file, as its easier to customize &amp; reuse it).</p><p><a href="https://registry.terraform.io/modules/terraform-google-modules/kubernetes-engine/google/latest">Terraform Registry</a></p><p><strong>STEP 12:- </strong>Lets Create variables.tf file &amp; describe the variables referenced in the previous file and their type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c597d70cec4c6e6fd33b8e391d0a64ef/href">https://medium.com/media/c597d70cec4c6e6fd33b8e391d0a64ef/href</a></iframe><p><strong>STEP 13:- </strong>Finally, Lets create the following variables.auto.tfvars file to specify values for the variables defined above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b1eeed3abd658a4c79dce9586715a3b/href">https://medium.com/media/4b1eeed3abd658a4c79dce9586715a3b/href</a></iframe><p>If you are confused about settings, you can follow mine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*yGKh1X0UrMnhYUKgf7bYXw.png" /></figure><p><strong>STEP 14:- </strong>Finally, we have created all the files which are necessary according to best practices, let’s run terraform initagain to install the required modules plugins. You can confirm the files added in .terraform/ directory before and after.</p><p>To get a list of resources Terraform will create to achieve the desired state mentioned in the configuration files we just wrote,Lets run:</p><pre># terraform plan</pre><pre>Acquiring state lock. This may take a few moments...</pre><pre>Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the <br>following symbols:<br>  + create</pre><pre>Terraform will perform the following actions:</pre><pre># module.gke.google_container_cluster.primary will be created<br>  + resource &quot;google_container_cluster&quot; &quot;primary&quot; {<br>      + cluster_ipv4_cidr           = (known after apply)<br>      + datapath_provider           = (known after apply)<br>      + default_max_pods_per_node   = 110<br>      + enable_binary_authorization = false<br>      + enable_intranode_visibility = (known after apply)<br>      + enable_kubernetes_alpha     = false<br>      + enable_legacy_abac          = false<br>      + enable_shielded_nodes       = true<br>      + endpoint                    = (known after apply)<br>      + id                          = (known after apply)<br>      + label_fingerprint           = (known after apply)<br>      + location                    = &quot;us-central1&quot;<br>      + logging_service             = &quot;logging.googleapis.com/kubernetes&quot;<br>      + master_version              = (known after apply)<br>      + min_master_version          = &quot;1.22.8-gke.200&quot;<br>      + monitoring_service          = &quot;monitoring.googleapis.com/kubernetes&quot;<br>      + name                        = &quot;terraform-gke&quot;<br>      + network                     = &quot;projects/annular-beacon-336307/global/networks/default&quot;<br>      + networking_mode             = (known after apply)<br>      + node_locations              = [<br>          + &quot;us-central1-a&quot;,<br>          + &quot;us-central1-b&quot;,<br>          + &quot;us-central1-c&quot;,<br>        ]<br>      + node_version                = (known after apply)<br>      + operation                   = (known after apply)<br>      + private_ipv6_google_access  = (known after apply)<br>      + project                     = &quot;annular-beacon-336307&quot;<br>      + remove_default_node_pool    = false<br>      + self_link                   = (known after apply)<br>      + services_ipv4_cidr          = (known after apply)<br>      + subnetwork                  = &quot;projects/annular-beacon-336307/regions/us-central1/subnetworks/default&quot;<br>      + tpu_ipv4_cidr_block         = (known after apply)</pre><pre>+ addons_config {<br>          + cloudrun_config {<br>              + disabled           = (known after apply)<br>              + load_balancer_type = (known after apply)<br>            }</pre><pre>............</pre><pre>Plan: 10 to add, 0 to change, 0 to destroy.</pre><pre>──────────────────────────────────────────────────────────────────</pre><p><strong>Seems everything is fine , Lets apply using:</strong></p><pre># terraform apply -auto-approve</pre><p>Once Terraform is done, Check the status of the GKE Cluster &amp; configure the kubectl command to connect using:</p><pre># gcloud container clusters list<br># gcloud container clusters get-credentials gke-cluster</pre><p>Thank you for reading! if you have any queries, you can PM me <a href="https://www.linkedin.com/in/mynameisameed/">here</a>!</p><p>Please do share, Clap &amp; Subscribe for more content on AWS |GCP|DevOps</p><figure><a href="https://faun.to/bP1m5"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCiLLad3dvZLwBa-B5cAVQ.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68f421d1212f" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/creating-gke-cluster-using-terraform-68f421d1212f">Creating GKE Cluster Using Terraform</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy AWS resources & Jenkins Pipeline using Terraform]]></title>
            <link>https://msameeduddin.medium.com/how-to-deploy-aws-resources-jenkins-pipeline-using-terraform-1a7991aa5b62?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a7991aa5b62</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 11:47:11 GMT</pubDate>
            <atom:updated>2021-08-03T16:37:12.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploy AWS resources &amp; Jenkins Pipeline using Terraform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*2jnebcgC89ZANOdD.png" /></figure><h3>What is Jenkins?</h3><p>Jenkins to the rescue! As a Continuous Integration tool, Jenkins allows seamless, ongoing development, testing, and deployment of newly created code. Continuous Integration is a process wherein developers commit changes to source code from a shared repository, and all the changes to the source code are built continuously. This can occur multiple times daily. Each commit is continuously monitored by the CI Server, increasing the efficiency of code builds and verification. This removes the testers’ burdens, permitting quicker integration and fewer wasted resources.</p><h3>What is Terraform?</h3><p>Terraform is a (Infra-as-code) tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.</p><p>Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.</p><p>The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc. on various platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*SPaVJVaiwxgVbdvN" /></figure><h3>How Terraform Works</h3><p>Terraform allows infrastructure to be expressed as code in a simple, human readable language called HCL (HashiCorp Configuration Language). It reads configuration files and provides an execution plan of changes, which can be reviewed for safety and then applied and provisioned.</p><p>Extensible providers allow Terraform to manage a broad range of resources, including IaaS, PaaS, SaaS, and hardware services.</p><blockquote><em>W</em><strong><em>ith that being said : How are we going to do it?</em></strong></blockquote><p><strong>Part 1:- Lets go through the Prerequisites:</strong></p><ul><li><a href="https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/">Create an AWS Account</a></li><li>Setup AWS User with Admin Role &amp; permissions in IAM</li><li>Install <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html">AWS CLI</a> on your PC &amp; setup Access &amp; Private Access key for ease of access &amp; later you dont have to configure AWS credentials in Terraform.</li><li>Install <a href="https://learn.hashicorp.com/tutorials/terraform/install-cli">Terraform</a></li><li>Install <a href="https://git-scm.com/downloads">Git</a></li><li>Install <a href="https://code.visualstudio.com/download">VisualStudioCode</a> (one of the best IDE tool)</li></ul><p><strong>Our Goal for this Project Labs:</strong></p><p>We are going to create 3 things:</p><ul><li>VPC with CIDR 10.0.0.0/16</li><li>2 subnets (public) with CIDR 10.0.1.0/24 and 10.0.2.0/24</li><li>An autoscaling group with Amazon Linux 2 ec2 instance (t3.small or t3a.small) with minimum of 2 instances and max of 3</li></ul><p>This kind of infrastructure usually takes longer time but we have a benefit using IaC (Infra-as-code tool) is Terraform to deploy our resources in much less time with our code.</p><p><strong>Part 2:- Time to Build:-</strong></p><ul><li>Perform all the Prerequisites open Visual Studio Code</li><li>I have Github repo <a href="https://github.com/mynameisameed/aws_terraform_jenkins_project.git"><strong>here </strong></a>which you can clone or fork it using the following command :$ git clone [forked repository url]</li><li>Make sure to<strong> </strong>update<strong> </strong>Jenkinsfile and line 24 to your forked from the repository URL.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*Nx96Adqs50wwhdoGTi-tjw.png" /><figcaption>jenkinsfile</figcaption></figure><blockquote><strong>We need a Backend &amp; Why? (Optional for this project)</strong></blockquote><blockquote>According to Terraform best practices its best make your state file as a secret and store it remotely. This adds better security &amp; also allows collaboration between other team members. When the state file is stored locally then surely you can share it with your team nor they cant access to it at ease.</blockquote><blockquote>Another benefit of using (Terraform’s) remote backend is “<strong>state locking”</strong>. In order to make sure your backend locks your state when someone is provisioning resources. (Whenever two team members try to make changes at the same time, the state file could become corrupted) S3 doesnt enable state locking function by default. If you like to add state locking to your S3 backend please review this <a href="https://www.terraform.io/docs/language/settings/backends/s3.html">Terraform documentation</a>.</blockquote><ul><li><a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/create-bucket.html">Create S3 Bucket</a> using the AWS CLI with a unique name &amp; add random numbers as bucket name.(AWS needs you to make it unique name around the world who uses S3 buckets)</li></ul><pre><strong>$ aws s3api create-bucket --bucket my-bucket --region us-east-1<br></strong>Make sure to put your unique name-number <strong>^^^</strong></pre><p>(or)</p><ul><li>If you have already created my S3 bucket in the past like me for remote-backend, lets just validate the name so i can put it in backend.tf file</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*10isLGifOsUng0onToxuEA.png" /><figcaption>aws s3 ls</figcaption></figure><ul><li>Open the <strong>backend.tf</strong> file in the repo you have downloaded and update the bucket name to your newly created bucket name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*g8ZPCxd8KgS0azYsyHNIrA.png" /></figure><ul><li>Before you initialize Terraform, make sure CMD terminal is pointing to the same directory where your repos are downloaded</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Ly_mTwCbVldhTwrBbFXoag.png" /><figcaption>cd &lt;path&gt;</figcaption></figure><p>&amp; run the following code to initialize terraform plugins, the modules &amp; to use remote backend service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*hp8GwcIp5ouzwOPqAkZS-A.png" /></figure><ul><li>Make sure the terraform is using the S3 backend by this command:</li></ul><pre><strong>$ aws s3api list-objects --bucket [bucket name]</strong></pre><ul><li>After using my bucket name i verified that state file does exist in s3 bucket:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*IXy8wWw0S8AQ5xmRPyWqpA.png" /></figure><h4>Part 3:- Verify the Code</h4><ul><li>Let’s apply the code to verify everything is working as it should before creating our pipeline.</li></ul><pre>$<strong> terraform fmt</strong> command is used to rewrite Terraform configuration files to a canonical format and style.</pre><pre>$<strong> terraform validate</strong> runs checks that verify whether a configuration is syntactically valid.</pre><pre>$ <strong>terraform plan</strong> command is used to create an execution plan.</pre><pre>$ <strong>terraform apply</strong> --auto-approve command is used to apply the changes required to reach the desired state of the configuration.<br>It will also write data to the .tfstate file &amp; <strong>auto-approve option</strong> doesnt asks you to <strong>type yes</strong> for executing creating of resources.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*sSKShtod5_mvAQfdsTOAoA.png" /></figure><pre>Once all the resources is deployed, Verify the resources are deployed,check one of the ec2 instances Public IP Address or alternatively you can check on ec2 web console.<br><strong>$ aws ec2 describe-addresses</strong></pre><ul><li>Once you are done verifying, Its time to delete the resources using the command:</li></ul><pre><strong>$ terraform destroy </strong><br>type &quot;<strong>yes</strong>&quot; to confirm it.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*uxzVHFmedOTNe5mw7DGw_g.png" /><figcaption>terraform destroy</figcaption></figure><ul><li>Before we go further make sure to push your code to Github repository</li><li>Once you verify that your modified code is working, push your changes to your GitHub.</li></ul><pre>$ <strong>git push origin master</strong></pre><p><strong>Part 4:- Its time to deploy Jenkins Server</strong></p><ul><li>You can create EC2 instance,configure &amp; install Jenkins manually we are going to make things as efficient &amp; faster we can.</li><li>In order to do that lets use an AMI from the AWS Marketplace.</li><li>There will be a small cost associated with this because of the instance type we are using for Jenkins.</li></ul><p><strong>Steps for Jenkins installation :-</strong></p><ol><li>Navigate to <a href="https://console.aws.amazon.com/marketplace/home?region=us-east-1#/search!mpSearch/search">AWS Marketplace</a>.</li><li>Click Discover products.</li><li>Search for “Jenkins” and select Jenkins Certified by Bitnami.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*WZfNtEZh1Omi7fYSJgHkIw.png" /></figure><p>4. After reviewing the AMI, you can see that this AMI &amp; EC2 instance class doesnt come under (t3a.small) free-tier of AWS account but its only very small amount being charged.</p><ul><li>Press <strong>Continue to Subscribe</strong> button. &gt; <strong>Continue to Configuration</strong> button &gt; <strong>Continue to Launch</strong> button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*yBEanfQvqxhqHJx-Cw8WzQ.png" /></figure><ul><li><strong>Choose Action</strong> select <strong>Launch from Website &gt; </strong>Select <strong>EC2 Instance Type</strong> select <strong>t3a.small</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*fb7LGllHGYX2ZQumomqcrQ.png" /></figure><ul><li>Leave the default <strong>VPC Settings</strong> (or customize it if you need.)</li><li>Leave the default <strong>Subnet Settings </strong>(or customize it if you need.)</li><li>For <strong>Security Group Settings</strong> select a security group that has SSH, HTTP, HTTPS configured. or you can create one by pressing <strong>Create New Based On Seller Settings</strong> button.</li><li>For <strong>Key Pair</strong> <strong>settings</strong> select a key pair that you’d like to use to SSH into the instance later or create one &amp; use it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*4s4xpUHE75zSFMnZ5QkI6A.png" /></figure><ul><li>Click <strong>Launch </strong>&amp; go to <strong>EC2 Console</strong>.</li><li>Select one of the instances which was deployed Select <strong>Actions</strong> &gt; <strong>Monitor and troubleshoot</strong> &gt; <strong>Get system log</strong>.</li></ul><blockquote>Note: If you don’t see anything in the system log wait 5–10 minutes and check again.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfAF-xv_cs9mWoJTYQEgKw.png" /></figure><ul><li>Refresh the console &amp; wait for few minutes to find the credentials in system logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gML7uKcVuJHpaH6tr6OmJg.png" /></figure><ul><li>In order to get it working,we need to manually install Terraform on our Jenkins server by SSH using public IP Address <strong>ssh bitnami@&lt;public ip&gt;</strong></li><li>Once you have successfully SSH into your Jenkins instance, open local browser &amp; open this <a href="https://www.terraform.io/downloads.html">link </a>scroll down to <strong>Linux</strong>.(as you already know this is a 64bit-linux flavour ec2 instance) <strong>just copy </strong><a href="https://releases.hashicorp.com/terraform/1.0.3/terraform_1.0.3_linux_amd64.zip"><strong>link</strong></a>.</li><li>Open your terminal &amp; paste the link with <strong>wget </strong>command &amp; run the following commands:</li></ul><pre>$ <strong>wget </strong><a href="https://releases.hashicorp.com/terraform/1.0.3/terraform_1.0.3_linux_amd64.zip"><strong>https://releases.hashicorp.com/terraform/1.0.3/terraform_1.0.3_linux_amd64.zip</strong></a></pre><pre>$ <strong>unzip terraform_1.0.3_linux_amd64.zip </strong>            <br>$ <strong>sudo mv terraform /usr/bin</strong><br>$ <strong>terraform -v</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*gqypsnzeFnURuBmDV9Lrjw.png" /><figcaption>jenkins server</figcaption></figure><ul><li>Sign in using the provided user name and password with the same public IP Address from the EC2 instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*YGd0ypA4iqx__a2FVG3Nzw.png" /></figure><p><strong>Part 5 :- Its time to Configure Terraform on Jenkins</strong></p><ul><li>Once you login, you will see <strong>Manage Jenkins</strong> from left hand navigation, click on it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*NrfbzHcj5oMNLwYu.png" /><figcaption>Courtesy <a href="https://medium.com/u/a37a3a009138">Troy Ingram</a></figcaption></figure><ul><li>Then go to Manage Plugins section &gt; go to available tab</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ypxe6gRJtOCPKpe9SrM5Ew.png" /></figure><ul><li>Search for terraform &amp; press Install without restart</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TG_YIr8Axo_ybIDcbI4HUg.png" /></figure><ul><li>Make sure it installed successfully</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vqkLThGVIVzbygah4kP8g.png" /></figure><ul><li>Click <strong>Manage Jenkins</strong> &amp; Click <strong>Global Tool Configuration</strong> from <strong>System configuration</strong> section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1B5AU7tYMQNc-V07eq8tQ.png" /></figure><ul><li>Scroll down to the <strong>Terraform</strong> section and click <strong>Add Terraform</strong>.</li><li>Enter a <strong>Name</strong> of your choice. I’m going to use “terraform-labs” to make things simple.</li><li>Ensure <strong>Install automatically </strong>is unselected. It’s selected by default.</li><li>For <strong>Install directory</strong> enter <strong>/usr/bin</strong>. Click <strong>Save</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kP62f4ShLRt3M3j16vYLUg.png" /></figure><h3>Manage AWS Credentials on Jenkins</h3><ul><li>Click <strong>Manage Jenkins &gt; </strong>then Click <strong>Manage Credentials</strong> in the <strong>Security</strong> section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXDWhvw7eOY5FEa5hEy6LA.png" /></figure><ul><li>Click <strong>Jenkins &gt; Global credentials (unrestricted)&gt;</strong> <strong>Add Credentials</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kiKByndPXiPU1KtPUCfDyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*aYMtXQYK5ByYuCsqC5idZQ.png" /></figure><ul><li>In <strong>Kind</strong> click drop-down select <strong>Secret text</strong>. For <strong>Secret</strong> paste your <strong>AWS Access Key</strong> for your user &amp; For <strong>ID</strong> type “<strong>AWS_ACCESS_KEY_ID</strong>”. click <strong>OK</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V56HhrEgSyKHF4jVkvbUkg.png" /></figure><ul><li>Repeat the same steps for your “<strong>AWS_SECRET_ACCESS_KEY</strong>” with secret key from aws key-pair of the AWS account you are currently using.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRpfRNcOXGigfijQLo0kpA.png" /></figure><h3>Part 6:- Configure Jenkins Pipeline</h3><ul><li>Go back to Dashboard &amp; Click on <strong>New Item</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vp5etJyWDwHn0ZFH7wQpiw.png" /></figure><ul><li>Enter an item name &amp; Then Select <strong>Pipeline </strong>&amp; click ok in bottom</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHkIlqrwaL_7lempg5EqYw.png" /></figure><ul><li>In <strong>Pipeline </strong>Section&gt; <strong>Select Definition</strong> drop down select <strong>Pipeline script from SCM</strong>.</li><li>Enter the following: <strong>SCM</strong>: Git<strong>| Repository URL</strong>: Your GitHub Repo with your Jenkinsfile</li><li><strong>Branch</strong>: Your primary branch</li><li><strong>Repository browser</strong>: Auto</li><li><strong>Script Path</strong>: “Jenkinsfile”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*6-OnnctAcgQNu9pnqNO60Q.png" /></figure><ul><li>Once done Click <strong>Save</strong>.</li></ul><h3>Part 7:- Run Jenkins Pipeline</h3><ul><li>Select <strong>Build with Parameters</strong> from the left navigation.</li><li>For the <strong>environment</strong> parameter type the name you want to use for your Workspace. The default is “terraform”. <strong>Check autoApprove</strong> and <strong>destroy</strong> unchecked. Click <strong>Build</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QlACyw_77AEq4QNl1evBSw.png" /></figure><ul><li>Now you should see the steps of the pipeline begin and it takes few minutes to complete each stage.</li><li>Review the plan &amp; then click <strong>Proceed</strong>.</li><li>While the final step is applied of our infrastructure you can click &amp; select the <strong>Logs</strong> button.</li><li>It will display in real time your infrastructure being created. Below is a snippet from the Apply step logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*iwaHbk2cbUUsi78j.png" /></figure><ul><li>You can see finally our Jenkins Pipeline has completed!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*r_nJ1pM3TYmhVtrlPD6xdQ.png" /><figcaption>Courtesy <a href="https://medium.com/u/a37a3a009138">Troy Ingram</a></figcaption></figure><h3><strong>Part 8:- Verify everything is working</strong></h3><ul><li>Navigate to the <strong>AWS Console</strong> &gt; <strong>EC2 Dashboard</strong> and grab the public IP of one of our t2.micro instances.</li></ul><blockquote>Check in the new tab and verify the website is working. Refresh the page few time to make sure the Application Load Balancer is able to switch between instances. Make sure terminate an instance as well to verify the Auto Scaling group is working.</blockquote><h3>Part 9:- Destroying Our Infrastructure</h3><ul><li>Another benefit of using Terraform with Jenkins is that it can destroy with one click, Build new Pipeline, but select this time <strong>destroy</strong> parameter.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*JMV4uQXA-lgi2wYz.png" /></figure><ul><li>Make sure all the infrastructure is being destroyed fully, also you can confirm it in ec2 console.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*rGhePnWp9mJRqqh_UXvTjQ.png" /><figcaption>Courtesy <a href="https://medium.com/u/a37a3a009138">Troy Ingram</a></figcaption></figure><blockquote><strong>You have reached end of this project, Feel free to take your time to experiment on this lab and share!</strong></blockquote><p><strong>Thank you for spending time on my post, Please Clap!| Comment | Share if you like my content. Im a DevOps Enthusiast practicing my skills, learning, trying to help and grow together, i make more weekly projects! You can follow me here &amp; on: </strong><a href="https://www.linkedin.com/in/mynameisameed/"><strong>https://www.linkedin.com/in/mynameisameed/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a7991aa5b62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Docker Containers with AWS ECS & Fargate]]></title>
            <link>https://aws.plainenglish.io/deploying-nginx-webserver-containers-using-aws-ecs-fargate-f6fb8ea2e2f3?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6fb8ea2e2f3</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[fargate]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Wed, 14 Jul 2021 15:15:58 GMT</pubDate>
            <atom:updated>2021-07-15T21:31:51.700Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is Fargate? What are Containers? How to deploy autoscalable Webservers on Docker containers.</h4><h3><strong>What is Fargate?</strong></h3><p>AWS Fargate is a technology that you can use with Amazon ECS to run <a href="https://aws.amazon.com/what-are-containers">containers</a>, without having to manage servers or clusters of Amazon EC2 instances. With Fargate, you no longer have to provision, configure, or scale clusters of virtual machines to run containers. This removes the need to choose server types, decide when to scale your clusters, or optimize cluster packing.</p><p>When you run your Amazon ECS tasks and services with the Fargate launch type or a Fargate capacity provider, you package your application in containers, specify the CPU and memory requirements, define networking and IAM policies, and launch the application. Each Fargate task has its own isolation boundary and does not share the underlying kernel, CPU resources, memory resources, or elastic network interface with another task. <a href="https://aws.amazon.com/fargate/faqs/">FAQs</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gttfm7hh20o5Jb4M.png" /><figcaption>Benefits of Fargate</figcaption></figure><h4><strong>What are Containers?</strong></h4><p>A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.</p><p><strong>Container </strong>images become containers at runtime and in the case of Docker containers — images become containers when they run on <a href="https://www.docker.com/products/container-runtime">Docker Engine</a>. Available for both Linux and Windows-based applications, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.</p><p>Most famous container Orchestration tool that probably being used on daily basis in the industry is Kubernetes(made by Google, but later donated to Open-Source Community). There are many flavours of Container Orchestration tools, such as Docker Swarm, Google’s Kubernetes Engine, AWS also has its managed container orchestrator called Amazon ECS (Elastic Container Service) and <strong>Amazon EKS (Elastic Kubernetes Service)</strong>.</p><h4><strong>What we are going to use</strong></h4><p><strong>Amazon ECS</strong>, it is one of managed container service that provided by AWS. ECS is proprietary service by AWS. The components that run ECS, including:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*TCvVsV-6INwjYyMJ5oPryQ.png" /><figcaption>diagram</figcaption></figure><ul><li><strong>Cluster </strong>: Logical cluster of ECS resource.</li><li><strong>Task Definitions</strong> : Set or collection of task that will used to run the application. It also contain Container Definition that will be used to define what container will be run. Task definition similar to <strong>Deployment </strong>if we compare this to Kubernetes terminology.</li><li><strong>Tasks </strong>: To prepare your application to run on Amazon ECS, Set or collection for container or more that has been defined on Task Definition. Task be described similar to <strong>Pod </strong>if we refers to Kubernetes terminology.</li><li><strong>Services </strong>: Service that will be used to expose Task Definition.</li><li><strong>Amazon ECR</strong>: Its a AWS Registry where containers are stored.</li></ul><p>There are various types in ECS terminology, called Launch Type that will be used as reference in what type , Task should be run. Some of Launch Types:</p><ul><li><strong>Fargate </strong>: Tasks will run as serverless.</li><li><strong>ECS instance</strong> : Where the Task will be run on Amazon ECS instance is either an External instance registered using ECS Anywhere or an Amazon EC2 instance.</li><li><strong>External </strong>: Task will be run on premise on virtual instance that has been registered to ECS cluster.</li></ul><p>In this scenario i will create an ECS cluster that will use Fargate as Launch Type. Container image will be pulled or downloaded from Docker Hub.</p><blockquote><strong>Note: This might incur additional charges by AWS.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*AehqjGZwi0hfjnTr.png" /><figcaption>This is the project reference diagram we are going to build.</figcaption></figure><h4><strong>Task 1</strong></h4><p>Open AWS Web Console. Go to <a href="https://console.aws.amazon.com/ecs/home?region=us-east-1#/clusters">ECS page</a> &amp; Create new cluster from Cluster menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*kW-_hkUj6oCetwUNBMg3cw.png" /><figcaption>Step 1- Create Cluster</figcaption></figure><p>Select cluster template, I&#39;m going to use <strong>Network Only </strong>because i want to use <strong>Fargate </strong>as a <strong>Launch Type</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kp9ppdfKD4bd1Mv_jQe1eg.png" /><figcaption>Step 1.1 — Select Networking</figcaption></figure><p>Configure cluster: with Cluster name as <strong>FG-StagingDemo</strong> Create a new VPC with CIDR and new subnets as well(choose your own CIDR range, depending on your requirement). And tag it with key Name for reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*xDV8y1Uy6Q3k4jjyFixmQA.png" /><figcaption>1.2- Configure cluster</figcaption></figure><p>Click Create and wait till the Launch status is completed like this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*gW1yrzfVwXqEEHwnGP-FzQ.png" /><figcaption>1.3- Status</figcaption></figure><p>Now verify that the cluster is created <a href="https://console.aws.amazon.com/ecs/v2/clusters?region=us-east-1">here </a>.</p><h4><strong>Task 2</strong></h4><p>Create a new Task on Task Definitions &amp; Run New Task Definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oOs3Qvb9YegDEyklF1sdCw.png" /></figure><p>Select launch type compatibility (in our case lets choose FARGATE).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7iI9mbfgbXqAUv0cZKFWng.png" /></figure><p>Before you go to next page we will need a <strong>Task Role, </strong>in order to create one go to <a href="https://console.aws.amazon.com/iamv2/home?#/roles"><strong>IAM</strong></a><strong> &gt; Create Role&gt; Choose a use case as &gt; Elastic Container Service &gt; Elastic Container Service Task.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*Kv4W5qMIybN-mlHUAa40rg.png" /></figure><p>Now attach permissions policies&gt; in search type task &gt;select <a href="https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2Fservice-role%2FAmazonECSTaskExecutionRolePolicy"><strong>AmazonECSTaskExecutionRolePolicy</strong></a><strong> &gt; skip to Review&gt; Give role name &amp; Create role.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*k6Wxx56oPIy-9gsjp0z_NA.png" /></figure><p>Now come back to <strong>Task 2</strong> &gt; Create a new Task Definition &gt; Name it &gt; Select Task Role we have created earlier &gt; skip to Task execution role&gt; and select the same one &gt; then Task size &gt; Task memory/CPU (you can set similar to mine below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*_T9QjFHukt_BBdPJ3irg4Q.png" /></figure><p>Now its time to click &amp; create Add container &gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Jb4bmtMAXuyPdNufHvZ5mA.png" /></figure><p>Its time to name the container &amp; select the image as <strong>nginx:latest &amp; click add</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*c9oxcVIieqU_wM3rMr8Qlw.png" /></figure><p>After that pop up will be closed.You can see the container going to be created &amp; other configurations will remain default and Add Tag with key Name. After that click Create button so that Task Definition will be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*RT3MRPnD6ssfH-d2oCcLGg.png" /></figure><p>Once its created it will show <strong>2 of 2 completed.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VaNNQpLp8g6iKBt10Wbyww.png" /></figure><h4><strong>Task 3</strong></h4><p>Next, go back to Clusters page.In created cluster, FG-StagingDemo, lets configure Service to run Task Definition. In tab Service, click Create button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tMphvzAFr7kVoBWYLiBHbw.png" /></figure><p>In Configure service, Choose <strong>FARGATE </strong>launch type and we will refer Task Definition that have been create before, which is FG-StagingDemo with revision number 1. Choose cluster, set name and number of tasks that will be running. In this early configuration, I will set number of tasks as 1 task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*ankxkfaAJk4rpi3Jqjkm-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*jNmQb_rzbJO-Zv0o3VdmXQ.png" /></figure><p>Choose Deployment type.we will choose Rolling update and will create new Tag with key Name. After that click Next.</p><p>Its time to configure the network VPC &amp; Security groups, you can select the VPC we have created earlier in <strong>Task 1</strong>, &amp; then select both subnets to add it , then click on Security Groups &gt;Edit&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*gkSd2MSkDxTpzsFJn13cww.png" /></figure><p>In Assigned security groups &gt; select create a new security group&gt; then name it &gt; add inbound rules &gt; HTTP &amp; HTTPS&gt; Source as Anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*EsUmmuDrQ822WDymTVNZ0w.png" /></figure><p>Then press next step and skip the Set Auto Scaling&gt; to Review &amp; Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*U2GA9WHW4pYrofg1NdghCg.png" /></figure><p>Verify the created <strong>Service</strong>, <strong>FG-StagingDemo</strong> has been successfully created. Wait a few moments until running task count will display 1 Fargate (as we have defined 1 number of task at previous service configuration).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7XXEmXxdz2nU8SY7MUE_w.png" /></figure><p>Its time to go to Task Details and find <strong>Public IP Address</strong> in order to check if the <strong>Nginx Webserver</strong> is accessible from outside or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RP6YsoW6-p1rhantVGEGQw.png" /></figure><p>As you can see we have in below screenshot that we have successfully deployed nginx webserver container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*l32nvQsTb8aLxYMxkpGC5g.png" /></figure><p>We can conclude that ECS cluster has been configured properly. Because container that we defined is running &amp; can be accessed. Let’s see what happens if the task is scaled up. Because in some circumstances, task might be scaled up or scaled down depends on the needs.</p><p>Go back to Service menu. Click Update button on the service page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*deMSjIfxVQ48Aetj6FzCXg.png" /></figure><p>Change Number of tasks to 2 &gt;Skip to review &gt; &amp; Update the Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qbdDWrjIc8-DuOJ0cwJEw.png" /></figure><p>Next, go back to Service menu. Then &gt; Tasks tab. Please make sure running task has been scaled up to 2 running task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*HWiZ-p52KNBdNceKZOe-rQ.png" /></figure><p>Under tasks click on the newly created <strong>Task </strong>&amp; copy the <strong>public IP address</strong> into browser &amp; compare both links working fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*MQtRhNBU-S2vyu2d-Fjt8Q.png" /></figure><p>Once you are done with this project make sure to delete the cluster &amp; resources (if its gets stuck make sure you manually delete the VPC we have created earlier).</p><h3>Conclusion</h3><p>We have successfully understood how to configure ECS cluster manually from scratch from AWS Web Console. Including all necessary components that need for ECS cluster configuration. We also have verify that ECS cluster has successfully created and container is running or can be public accessed.</p><p>Thank you for taking the time to read this, I hope you have found it useful. If so, be sure to let me know in the comments.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6fb8ea2e2f3" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/deploying-nginx-webserver-containers-using-aws-ecs-fargate-f6fb8ea2e2f3">Deploy Docker Containers with AWS ECS &amp; Fargate</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform on GCP :Creating a Webserver]]></title>
            <link>https://medium.com/geekculture/terraform-on-gcp-creating-a-webserver-762a20bb5424?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/762a20bb5424</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Mon, 28 Jun 2021 17:56:51 GMT</pubDate>
            <atom:updated>2021-06-30T17:27:04.346Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Deploying a Webserver with </strong>Terraform on GCP</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Umf2M6FqE69SIM1b.jpg" /><figcaption>Picture by <a href="https://hackersandslackers.com/author/david/">David Aquino</a></figcaption></figure><p>In this project, we will learn how to use Terraform with GCP but also create a Apache Webserver on the instance (f1-micro) using bash script.</p><p>Overview of the following products &amp; services being used in this project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0kXiIsDaeIktBncB.png" /></figure><blockquote><strong>Terraform</strong></blockquote><blockquote>Terraform is an open-source cloud agnostic infrastructure as code tool that provides a consistent CLI workflow to <strong>manage hundreds of cloud vendor-specific services</strong>. Terraform codifies cloud APIs into declarative configuration files.Most Popular cloud providers like GCP|AWS|Azure all provide their own version of Infra-as-code tools:</blockquote><ul><li>Cloud Deployment Manager-GCP</li><li>Cloud Formation- AWS</li><li>Azure Resource Manager- Azure</li></ul><blockquote><strong>Its Benefits:</strong></blockquote><ul><li>It provisions infrastructure seamlessly</li><li>It updates infrastructure with ease</li><li>It destroys infrastructure without hassle</li><li>It checks codes errors with just click of a button</li><li>It plans out infrastructures prior to deployment</li><li>It tracks records from state file</li></ul><p>You can find all the related Terraform-GCP Modules <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs">here</a>.</p><h3><strong>Step 1:-</strong></h3><p>There are a few out package managers you can use to install Terraform on Windows. My favorite is <a href="https://chocolatey.org/">Chocolatey</a>. It makes installing, removing and updating software as simple as a one-line command, and Terraform is no exception to that.</p><p>To install Terraform with <a href="https://adamtheautomator.com/install-chocolatey/">Chocolatey</a>, do the following steps:</p><ol><li>Open a CMD/PowerShell prompt as an administrator and install Chocolatey using the command from <a href="https://chocolatey.org/install">their install page</a>.</li><li>Once that is complete, run choco install terraform -y on the end to auto-agree to installing it on your device.</li></ol><p>After that command runs, you will get something like this:</p><pre>Chocolatey v0.10.13<br>2 validations performed. 1 success(es), 1 warning(s), and 0 error(s).<br>Installing the following packages:<br>terraform<br>By installing you accept licenses for the packages.<br>Progress: Downloading terraform 0.12.6... 100%<br>terraform v0.12.6 [Approved]<br>Downloading terraform 64 bit from &#39;https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_windows<br>Download of terraform_0.12.6_windows_amd64.zip (15.32 MB) completed.<br>--SNIP--</pre><h3>Step 2:-</h3><p>We need a IDE to write Terraform configuration and modules for GCP. Im going to use my favourite <a href="https://code.visualstudio.com/download">Visual Studio Code</a> &amp; open Ctrl + ~ to open the terminal inside it and create a Folder called “Terraform on GCP”</p><p>Prerequisites :</p><ul><li>GCP service account key and the file in path location</li><li>GCP project ID, you can run <em>gcloud projects list</em> to find it</li><li>Setting the default region for resources being built with terraform</li><li>Setting the default zone for resources being built with terraform</li></ul><h3>GCP Service Account</h3><p>We will need a <strong>GCP Service Account</strong> with <strong>Compute Admin (roles/compute.admin)</strong> permissions and the <strong>JSON file of the Service Account inside the </strong>“Terraform on GCP” folder.</p><h3>Bucket for Terraform Backend</h3><p>We need to create a Storage Bucket inside the GCP in order to use it as remote-backend &amp; store our state file in it.</p><h3>Cloud Storage API enabled</h3><p>We select our root project, type <strong>Cloud Storage API </strong>on the search box and select <strong>Cloud Storage API &amp; Compute Engine API</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*q5lu43mLI0Cuv1uJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDUyzdfqYHaTJ8riRFXfZg.png" /></figure><p>If the API is disabled, we click on the <strong>ENABLE</strong> button to enable it.</p><p>Inside “Terraform on GCP” Folder:</p><p>Firstly we will define the configuration of remote backend:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc94a4f196aee0d39a92aa38ce8d19cc/href">https://medium.com/media/cc94a4f196aee0d39a92aa38ce8d19cc/href</a></iframe><p>Lets create provider.tf which helps you define which provider you wanna use with your terraform, also we will define default region &amp; zone, In our case we add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d49f2ea1a882e8fbe8d8d78b781303c/href">https://medium.com/media/5d49f2ea1a882e8fbe8d8d78b781303c/href</a></iframe><p>We also need</p><p>This lets Terraform know what resources to query and the name of the resource inside Terraform.</p><p><strong>Name</strong>: Custom name of the VM inside GCP.</p><p><strong>Machine_types</strong>: This is basically a combination of CPU | RAM &amp; GPU helps us choose different classes of instances available on GCP, a full list can be found <a href="https://cloud.google.com/compute/docs/machine-types">here</a>.</p><p><strong>Tags: </strong>Add network tags.</p><p><strong>Boot_disk: </strong>Select the image to use (in our case we will use default)</p><p><strong>metadata_startup_script:</strong> Add your startup script to custom install dependencies.</p><p><strong>Scheduling</strong>: Since this is going to be temporary machine, I made the VM a preemptible. If you decide to do the same, automatic_restart must equal false.</p><p><strong>Network_interface</strong>: This helps us defines the network the VM should use.</p><p><strong>Network</strong>: What VPC your VM should use.</p><p><strong>access_config</strong>: Leave this blank as it will automatically create an external ephemeral ip.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7dcb997e42f07aa10b41d7cd55603e5/href">https://medium.com/media/b7dcb997e42f07aa10b41d7cd55603e5/href</a></iframe><h3>Finally we need a startup script</h3><p>The start up script is very simple bash script. It allows the instance to update packages and install Apache Web-Server, then I pushed the changes to the startup.sh script. Once done, add the file path to the Terraform configuration file like the example above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f299c0183eeca821f02b10b10c6e1e9/href">https://medium.com/media/4f299c0183eeca821f02b10b10c6e1e9/href</a></iframe><h3>Time to deploy our resources using Terraform commands:</h3><pre>$ <strong>terraform init</strong></pre><p>This will initialize and install necessary plugins to make terraform run.</p><p>Makes sure to <strong>validate</strong> the syntax of the <strong>all terraform</strong> files in your directory</p><pre>$ <strong>terraform validate</strong><br>Success! The configuration is valid.</pre><p>Then, we will plan our terraform infrastructure to make sure what resources will be deployed using this code, shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca0f97feba1547eb65918122b25bcb39/href">https://medium.com/media/ca0f97feba1547eb65918122b25bcb39/href</a></iframe><p>After reviewing the code we will finally do terraform apply — auto-approve to accept and deploy resources declared in terraform files above on GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*Tq1wx7EPT4Dx2cfXanxUOw.png" /></figure><p>(Optional) Confirm it by going to GCP console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q84vkD4Dx915HFsawWPCmw.png" /></figure><h3>Confirm Apache was installed</h3><p>Navigate to the “EXTERNAL_IP” and if the startup script was successful you will see your web server!</p><p>Time to Destroy everything we have build using :</p><pre>$ <strong>terraform destroy</strong><br>.<br>.<br>   Enter a value: yes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*aFQEw-QzpFJAjED4wFuGQA.png" /></figure><p>Thank you for spending time on my post, Please do Clap! Comment &amp; Share if you like. Im a DevOps Enthusiast practicing my skills, learning, trying to help and grow together &amp; You can follow me on: <a href="https://www.linkedin.com/in/mynameisameed/">https://www.linkedin.com/in/mynameisameed/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=762a20bb5424" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/terraform-on-gcp-creating-a-webserver-762a20bb5424">Terraform on GCP :Creating a Webserver</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying AWS EKS Cluster With Terraform]]></title>
            <link>https://faun.pub/deploying-aws-eks-cluster-with-terraform-97b5692d9f60?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/97b5692d9f60</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Mon, 21 Jun 2021 17:44:35 GMT</pubDate>
            <atom:updated>2021-10-18T10:58:26.087Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*LqmUbWDGUDloteUs" /></figure><h4>This is a 2 part series:-</h4><h3>Let&#39;s first talk about :</h3><p><strong>What is Elastic Kubernetes Service (Amazon EKS)</strong></p><p>Fully managed Kubernetes control plane</p><p>Amazon EKS is a managed service that makes it easy for you to use Kubernetes on AWS without needing to install and operate your own Kubernetes control plane.</p><h3>How it works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*wHBI-3wbqxm49mN2P0cNUA.png" /></figure><p>Amazon EKS exposes a Kubernetes API endpoint. Your existing Kubernetes tooling can connect directly to EKS managed control plane. Worker nodes run as EC2 instances in your account.</p><h3>Why use Amazon EKS?</h3><h3>Hybrid container deployments</h3><p>Run highly available and scalable Kubernetes clusters on AWS, while maintaining full compatibility with your Kubernetes deployments running anywhere else.</p><h3>Microservices</h3><p>Easily run microservices applications with deep integrations to AWS services, while getting access to the full suite of Kubernetes functionality and popular open source tooling.</p><h3>Application migration</h3><p>Easily containerize and migrate existing applications to Amazon EKS without needing to refactor your code or tooling.</p><h3>Batch processing</h3><p>The Kubernetes Jobs API lets you run sequential or parallel workloads on your Amazon EKS cluster. These workloads can be run on Amazon EC2 On-Demand Instances, Reserved Instances, or Spot Instances.</p><p>For more details:</p><p><a href="https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html">What is Amazon EKS?</a></p><h3>What is Terraform?</h3><p>Terraform is a (Infra-as-code) tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.</p><p>Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.</p><p>The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc. on various platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZVNbTPPZEfTt8vlC" /><figcaption>How it Works</figcaption></figure><h3>How Terraform Works</h3><p>Terraform allows infrastructure to be expressed as code in a simple, human readable language called HCL (HashiCorp Configuration Language). It reads configuration files and provides an execution plan of changes, which can be reviewed for safety and then applied and provisioned.</p><p>Extensible providers allow Terraform to manage a broad range of resources, including IaaS, PaaS, SaaS, and hardware services.</p><blockquote><strong>With that being said : How are we going to do it?</strong></blockquote><p><strong>Using repeatable Terraform modules to provision an EKS cluster with scalable, highly available, and fault-tolerant supporting architecture.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PclNKrDFpPsRfdUq.png" /><figcaption>learn.hashicorp.com</figcaption></figure><p>As you can see the changes in cloud technologies are frequent including Terraform, the biggest issue in building modules and resources is the dependability, compatibility &amp; reliability of the code being used. Projects can quickly go off the rails if one of your modules is dependent on a resource that is deprecated. To find the most recent to-date and reliable example code when building custom projects, I find both <a href="https://registry.terraform.io/">Terraform Registry</a> and <a href="https://learn.hashicorp.com/terraform">Terraform Learn</a> contain lots of resources that can work with each other and with the latest version of Terraform.</p><p><strong>Today, we are going to use Terraform to build two AWS solutions with modules:</strong></p><ol><li>A VPC with public and private subnets, both with autoscaling groups of EC2 instances, and a load balancer to work with the private subnet.</li><li>An EKS cluster with a capacity of 2 and a random string to generate the cluster name, and outputs for the cluster’s name and endpoint.</li></ol><p>The Terraform plan for these solutions should be able to run on your local environment and Terraform Cloud.</p><p>For this project, I will be using Hashicorp’s Github repository “<a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster"><strong>learn-terraform-provision-eks-cluster</strong></a><strong>” </strong>which I forked.</p><p><strong>Prerequisites </strong>for this project are accounts and administrative-level credentials for AWS Cloud, GitHub and the AWS CLI configured on your local or WSL machine ; a Terraform-friendly IDE such as VisualStudio Code and kubectl and Git. If you dont know know how to install Terraform &amp; integrate with AWS use the following link :</p><p><a href="https://faun.pub/how-to-create-iam-user-policy-using-terraform-on-aws-70bf178bd7df">How to Create IAM User &amp; Policy using Terraform on AWS</a></p><h3>Step 1: Write the Code &amp; Configure</h3><p>Its time to clone the Github repo <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster">link </a>to your local machine, cd into the new directory and view the files and their contents.</p><pre># git clone <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster">https://medium.com/r/?url=https%3A%2F%2Fgithub.com%2Fhashicorp%2Flearn-terraform-provision-eks-cluster</a></pre><p>In the new directory, you will find files used to provision VPC, security groups, and an EKS cluster. The <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/master/vpc.tf">vpc.tf</a> provisions a new VPC, subnets and availability zones using the <a href="https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/2.32.0">AWS VPC Module</a> to have a seperate networking for this project. The <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/master/security-groups.tf">security-groups.tf</a> provisions the security groups (which acts as a firewall for your resources) that will be used by the EKS cluster. The <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/master/eks-cluster.tf">eks-cluster.tf</a>, <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/master/security-groups.tf">kubernetes.tf</a>, and <a href="https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/master/security-groups.tf">versions.tf</a> together provision all the resources including IAM Roles, Worker Groups, AutoScaling Groups, etc which are required to set up an EKS cluster using the <a href="https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/11.0.0">AWS EKS Module</a>.</p><p>Now, we will set up a remote backend for the local copy of the terraform files on AWS S3. Create a workspace on Terraform using Git version control and your newly forked repository. In the Variables tab for the workspace, add the variables for your “aws_access_key_id” and “aws_secret_access_key” and mark them both as “Sensitive” before saving.</p><p>Back in the IDE, add the code for your remote backend — the new Terraform workspace — to one of the Terraform files, for example:</p><p>Backend type: S3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*hn7M2K1wANoOlquGEh6WeA.png" /></figure><p>and backend.tfvars is a configuration file to use with terraform to use remote backend to store the state file in S3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*JO89oc_U8KW0dpZN3FaHTQ.png" /></figure><blockquote>Note: Using AWS CLI Create a S3 bucket using command :<strong>aws s3 mb s3://mybucket </strong>&amp; add the s3 name path &amp; region into <strong>backend.tfvars</strong>file</blockquote><p>Run “<strong>terraform init -backend-config= &quot;backend.tfvars”</strong>” in CLI to initialize &amp; make terraform use the remote backend on AWS S3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*Go91KfojCKRx6FmKKj8eYg.png" /></figure><p>Ensure your .tf files are properly formatted with correct syntax by running “<strong>terraform fmt</strong>” and “<strong>terraform validate</strong>”.When everything is formatted and validated, commit any changes to your local git repository.</p><h3>Step 2: Plan and Troubleshoot</h3><p>Run “<strong>terraform plan</strong>” in your Local CLI to create a planned resource deployment. The Terraform Plan will appear on the Terraform workspace, and Terraform will give you this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*-MJ__jVqK4_7BYloDo0HSQ.png" /><figcaption>Terraform plan</figcaption></figure><p>If successful, “Plan finished” will appear with a list of the number of resources to add, change, and destroy. This Plan tells us our build will add 51 resources.</p><h3>Step 3: Apply, Confirm, and Destroy</h3><p>The complexity and number of resources being added, you will have to wait about 10 minutes after confirming the “Apply” run. At this point, you can also enter a note or description of this run. The progress log will appear just as it does on the CLI, listing the resources it is creating and the elapsed time for each action.</p><pre><strong># terraform apply</strong></pre><pre><strong>Enter a value: yes</strong></pre><pre>random_string.suffix: Creating…<br>random_string.suffix: Creation complete after 0s [id=EVzeoaLy]<br>module.vpc.aws_vpc.this[0]: Creating…<br>module.eks.aws_iam_role.cluster[0]: Creating…<br>module.eks.aws_iam_policy.cluster_elb_sl_role_creation[0]: Creating…<br>.<br>.<br>.</pre><pre>Apply complete! Resources: 51 added, 0 changed, 0 destroyed.</pre><p>Once the Apply is finished, confirm all the resources successful created by using following command: <strong>terraform state list</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FMHABlsTiEK3eiA0jIDcow.png" /></figure><p>You can also confirm this on AWS Console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PHNgYB9FQSVojiBxUS0qA.jpeg" /></figure><p>EKS Cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZi7wZQB5oXtZIWDl4Gprg.jpeg" /></figure><p>Your VPC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0q1hM3kFxo6eBtzinKLKQ.jpeg" /></figure><p>Subnets Created as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-EFtNQe0jNnJBWuNzILyw.jpeg" /></figure><p>Launch Configurations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2hDgJ3eStMKQM6T8OM9og.jpeg" /></figure><p>Instances for EKS cluster to run on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vbrtlq-mtBVDE4aQB2alYw.jpeg" /></figure><h3>Step 4: Destroy and Confirm!</h3><p>Once you are done using the EKS Cluster and no need of these resources &amp; dont want to get billing charges on your AWS Account, Its time to destroy them using the “<strong>terraform destroy</strong>” command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4YMBLDqsj4QCPM8ebBY5g.png" /></figure><p>Next, confirm on the AWS console that the resources have been deleted. The Terraform build has been properly destroyed when you run “<strong>terraform state list</strong>” again.</p><p>Voila! Just using your local machine you are able to deploy AWS EKS Cluster &amp; its dependencies with using Infra-as-code tool called Terraform</p><p>In next project, i will show you how to deploy containerized applications…</p><p>Thanks for reading my post, Im passionate about DevOps &amp; love to learn and help others on various topics</p><p>Feel free to give your feedback with Comment, Clap <a href="https://medium.com/@msameeduddin">Follow me</a> &amp; Share,</p><p>You can also follow me on :</p><p><a href="https://www.linkedin.com/in/mynameisameed/">Mohammed Sameed Uddin - Implementation Project Manager - AT&amp;T | LinkedIn</a></p><figure><a href="https://faun.to/i9Pt9"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_MOgMTr_f1N4qHN_R7KVA.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97b5692d9f60" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/deploying-aws-eks-cluster-with-terraform-97b5692d9f60">Deploying AWS EKS Cluster With Terraform</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create Docker Container using Jenkins CI/CD Tool]]></title>
            <link>https://faun.pub/how-to-create-docker-container-using-jenkins-ci-cd-tool-1b4360d604a5?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b4360d604a5</guid>
            <category><![CDATA[project-based-learning]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Fri, 21 May 2021 18:45:42 GMT</pubDate>
            <atom:updated>2021-05-29T08:43:21.739Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create Jenkins CI/CD Tool using Docker Container</h3><h3>What is a Docker Container?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mpu7_jSiEIMB9O2T" /></figure><p>A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.</p><p>Container images become containers at runtime and in the case of Docker containers — images become containers when they run on <a href="https://www.docker.com/products/container-runtime">Docker Engine</a>. containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.</p><p>Docker containers that run on Docker Engine:</p><ul><li><strong>Standard:</strong> Docker created the industry standard for containers, so they could be portable anywhere</li><li><strong>Lightweight:</strong> Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs</li><li><strong>Secure:</strong> Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*a2EkdyxPjzUyzDcs.png" /><figcaption>Jenkins</figcaption></figure><h3>What is Jenkins?</h3><p>Jenkins to the rescue! As a Continuous Integration tool, Jenkins allows seamless, ongoing development, testing, and deployment of newly created code. Continuous Integration is a process wherein developers commit changes to source code from a shared repository, and all the changes to the source code are built continuously. This can occur multiple times daily. Each commit is continuously monitored by the CI Server, increasing the efficiency of code builds and verification. This removes the testers’ burdens, permitting quicker integration and fewer wasted resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*INYM78vPKyLouZQc.png" /><figcaption>Jenkins+Docker</figcaption></figure><h3>Step 1: Let’s create a container in your machine.</h3><p>You need docker installed and running in your machine.</p><p>Use the following link to install and setup Docker: <a href="https://docs.docker.com/engine/install/ubuntu/">Ubuntu</a> | <a href="https://docs.docker.com/engine/install/centos/">CentOS</a></p><p>Once you are done with setting-up Docker</p><p>Execute this command:</p><pre><em>docker run -it -v /var/run/docker.sock:/var/run/docker.sock -p8080:8080 jenkins/jenkins:lts</em></pre><p>This command will download and run a jenkins in your machine.</p><p>Wait some time, The console will show a lot of messages. When jenkins was initialized, the console will show you an admin password to start jenkins initial setup. The text with password is:</p><pre>*************************************************************<br>*************************************************************<br>*************************************************************Jenkins initial setup is required. An admin user has been created and a password generated.<br>Please use the following password to proceed to installation:<br>This command will download and run a jenkins in your machine.</pre><pre>Wait some time, The console will show a lot of messages. When jenkins was initialized, the console will show you a admin password to start jenkins initial setup. The text with password is:</pre><pre>*************************************************************<br>*************************************************************<br>*************************************************************Jenkins initial setup is required. An admin user has been created and a password generated.<br>Please use the following password to proceed to installation:<br>a3c76c0cc3e541ff94b3670c22995342<br>This may also be found at: /var/jenkins_home/secrets/initialAdminPassword*************************************************************<br>*************************************************************<br>*************************************************************</pre><p>You can access your jenkins in <a href="http://localhost:8080/">http://localhost:8080/</a>. You will see this screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*ERnEtkZmXxlOBtaE.png" /></figure><p>Put the admin password in input on the screen and press continue.</p><p>In next screen, click “Install suggested plugins”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*3tIT1PPqusRy_cc5_6hIJQ.png" /></figure><p>Wait for the plugins installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*8dSl3b2yRUQeVx6gW8YLRA.png" /></figure><p>Now, create a user for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*spQNm8oHPC4cCIS0fiZS6Q.png" /></figure><p>We finish the installation, click “Start using Jenkins”</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Let’s install two plugins:</p><ul><li>blue-ocean plugin to beautify your Jenkins. This plugin better the usability of Jenkins and focus in pipelines scripts.</li><li>locale plugin to Jenkins always show English text. You don’t need install this, but i suggest install to search errors directly in English.</li></ul><p>Go to Plugin Manager again and search for locale</p><p>To install plugins:<br>- In-home of Jenkins, click in <strong>Manage Jenkins</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwhqrmSnYuMMfG43cLekRQ.png" /></figure><p>Click in <strong>Manage Plugins</strong>:</p><p>In Plugin manager, you need to click on the <strong>Available</strong> tab and after, load the tab, search the plugins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFJxCq3uH3Q7kdSiAKaKwQ.png" /></figure><p>Search for <strong>locale</strong>, mark the checkbox, and click on the install button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*J3bbSOIPdySst6wNofc2gw.png" /></figure><p>After install locale, go to Home &gt; Manage Jenkins &gt; Configure System</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a74GT6CcN3oGkyjtMsMSWQ.png" /></figure><p>Search for locale. Input “<strong>en” </strong>in “<strong>Default language” </strong>and check<strong> “ignore browser preference and force this language to all users”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E71yx2IZhl7mKAW7EvZkfg.png" /></figure><p>Locale Plugin installed and configured, let&#39;s install Blue ocean.<br>Go Back to Jenkins home &gt; Manage Jenkins &gt;Manage Plugins. In the Available tab, search for Blue Ocean and install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YS1zh8X8VyyyrHwycfngfw.png" /></figure><p>All done. But you see the visual without the blue ocean plugin, let’s use it.<br>In Jenkins home, Click in “<strong>Open Blue Ocean</strong>” (left menu)</p><p>Now, you will see a screen like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6XzNZ2LjKkgNUKwPPwDcw.png" /></figure><p>All Right, now we have Jenkins installed and we are using blue ocean plugin to have a better experience in your pipelines.</p><p>In the next blog, we will create a CI/CD pipeline &amp; much more advanced content based on Jenkins|Ansible|Docker|Kubernetes…</p><blockquote>Thank you for reading, Do follow, share, clap! &amp; comment so i can make more informative projects &amp; labs.</blockquote><figure><a href="https://faun.to/i9Pt9"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_MOgMTr_f1N4qHN_R7KVA.png" /></a></figure><p>Join FAUN: <a href="https://faun.to/i9Pt9"><strong>Website</strong></a><strong> </strong>💻<strong>|</strong><a href="https://faun.dev/podcast"><strong>Podcast</strong></a><strong> </strong>🎙️<strong>|</strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong>|</strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong>|</strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷|<a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>🗣️<strong>|</strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin Group</strong></a><strong> </strong>💬<strong>|</strong> <a href="https://faun.dev/chat"><strong>Slack</strong></a> 📱<strong>|</strong><a href="https://thechief.io/"><strong>Cloud Native</strong> <strong>News</strong></a><strong> </strong>📰<strong>|</strong><a href="https://linktr.ee/faun.dev/"><strong>More</strong></a><strong>.</strong></p><p><strong>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b4360d604a5" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/how-to-create-docker-container-using-jenkins-ci-cd-tool-1b4360d604a5">How to Create Docker Container using Jenkins CI/CD Tool</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy AWS resources with Boto3, Terraform, and CloudFormation]]></title>
            <link>https://aws.plainenglish.io/creating-vpc-using-boto3-terraform-cloudformation-and-both-af741a8afb3c?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/af741a8afb3c</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Fri, 07 May 2021 18:21:33 GMT</pubDate>
            <atom:updated>2021-07-17T21:35:19.638Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to Deploy AWS resources using Boto3, Terraform, and CloudFormation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*PqEPyNixwLwQpdu7.png" /><figcaption>Workflow IAC with AWS</figcaption></figure><p>Lets talk about all three before we jump in:</p><h4><strong>Boto3 (AWS SDK for Python)</strong></h4><p>You use the AWS SDK for Python (Boto3) to create, configure, and manage AWS services, such as Amazon Elastic Compute Cloud (Amazon EC2) and Amazon Simple Storage Service (Amazon S3). The SDK provides an <strong>object-oriented API</strong> as well as <strong>low-level access to AWS services.</strong></p><h4><strong>Terraform</strong></h4><p>Terraform is an open-source infrastructure as code tool that provides a consistent CLI workflow to <strong>manage hundreds of cloud vendor-specific services</strong>. Terraform codifies cloud APIs into declarative configuration files.</p><p><strong><em>Tips:</em></strong></p><ul><li>It provisions infrastructure seamlessly</li><li>It updates infrastructure with ease</li><li>It destroys infrastructure without hassle</li><li>It checks codes errors with just click of a button</li><li>It plans out infrastructures prior to deployment</li><li>It tracks records from state file</li></ul><h4><strong>CloudFormation</strong></h4><p>AWS CloudFormation gives you an easy way to model a collection of related AWS and third-party resources, provision them quickly and consistently, and manage them throughout their lifecycles, by treating infrastructure as code. A CloudFormation template describes your desired resources and their dependencies so you can launch and configure them together as a stack. You can use a template to create, update, and delete an entire stack as a single unit, as often as you need to, instead of managing resources individually. You can manage and provision stacks across multiple AWS accounts and AWS Regions.</p><p><strong><em>Note:</em></strong> CloudFormation is for AWS proprietary IAC tool in other word, AWS native template which means its can only be used on AWS Platform. So it may not b a good fit for you if AWS is not your provider of Cloud.</p><h4><strong>Terraform + CloudFormation</strong></h4><p>Finally With AWS, we can utilize CloudFormation. With other cloud providers, we can take advantage of other resources. Either way, terraform could be seen as an IaC hub for all our Cloud projects, we can</p><ul><li>provision infrastructure seamlessly</li><li>update infrastructure with ease</li><li>destroy infrastructure without hassle</li><li>check codes errors with click of a button</li><li>plan out infrastructures prior to deployment</li><li>track records from state file</li></ul><p>Doing all of above using Terraform and build up infrastructure along with native IaC tool from any specific almost all Cloud providers!</p><p><strong><em>Reminder:</em></strong> This should be part 1 of the project since I will dive in AWS CDK with Terraform and attempt to provision VPC using CDK with Terraform.</p><p>Here are the options I would touch upon throughout this project</p><h4>Prerequisites</h4><ul><li>An <a href="https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fportal.aws.amazon.com%2Fbilling%2Fsignup%2Fresume&amp;client_id=signup">AWS account</a> — with non-root user (take security into consideration)</li><li>Your Local Machine Windows 10 with <a href="https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe">Python3 </a>installed or just search &amp; Install Python from Windows Store.</li><li>Install Visual Studio Code <a href="https://code.visualstudio.com/download">here</a>.</li><li>AWSCLI installed <a href="https://awscli.amazonaws.com/AWSCLIV2.msi">link</a> <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html">here</a>.</li><li>Install Terraform <a href="https://www.terraform.io/downloads.html">here</a></li></ul><p>Let’s start work on them one by one.</p><h3>Creating a non-root user</h3><p>Based on AWS best practice, root user is not recommended to perform everyday tasks, even the administrative ones. The root user, rather is used to to create your first IAM user, groups and roles. Then you need to securely lock away the root user credentials and use them to perform only a few account and service management tasks.</p><p><strong><em>Note: </em></strong><em>If you would like to learn more about why we should not use root user for operations and more about AWS account, please find more </em><a href="https://medium.com/paul-zhao-projects/aws-security-deep-dive-7c8b32ce933d?source=friends_link&amp;sk=765459c3f164ffe14f45ee8d2de0e2ef"><em>here</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*0MSxmwFsltGGN90gG3K30g.png" /><figcaption>First Create Root User (if you already have skip and login)</figcaption></figure><ul><li>Secondly, Create a user under IAM</li><li>Choose programmatic access for that user before creation</li><li>when it says Success download the CSV file for credentials for later use.<strong>(Access key ID and Secret access key)</strong></li><li>Verify the installation by opening VS Code &amp; hold ctrl and ~ to open powershell within.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fdpcWaOrHPqLrvRoqsLhg.png" /></figure><p>Then use the following commands verify the installation</p><pre><strong>$ aws --version</strong><br>aws-cli/2.2.1 Python/3.8.8 Windows/10 exe/AMD64 prompt/off</pre><p>To use<strong> AWS cli</strong>, we need to configure it using <strong>AWS Access Key</strong>, <strong>Secret Access Key</strong>, <strong>default region</strong> and<strong> output format:</strong></p><pre><strong>$ aws configure</strong><br>AWS Access Key ID [****************46P7]:<br>AWS Secret Access Key [****************SoXF]:<br>Default region name [us-east-1]:<br>Default output format [json]:</pre><p>Now it is time to install Terraform (alternative methods <a href="https://adamtheautomator.com/terraform-windows/">link</a>).</p><h3>The Easy Way</h3><p>Phew, that was a lot of work! That would be awful to do every time you had to install new software on your device. Let’s use a package manager instead. There are a few out package managers you can use to install Terraform on Windows. For Windows, my favorite is <a href="https://chocolatey.org/">Chocolatey</a>. It makes installing, removing and updating software as simple as a one-line command, and Terraform is no exception to that.</p><p>To install Terraform with <a href="https://adamtheautomator.com/install-chocolatey/">Chocolatey</a>, do the following steps:</p><ol><li>Open a CMD/PowerShell prompt as an administrator and install Chocolatey using the command from <a href="https://chocolatey.org/install">their install page</a>.</li><li>Once that is complete, run choco install terraform. If you like, you can also put -y on the end to auto-agree to installing it on your device.</li></ol><p>After that command runs, you will get something like this:</p><pre>Chocolatey v0.10.13<br>2 validations performed. 1 success(es), 1 warning(s), and 0 error(s).</pre><pre>Installing the following packages:<br>terraform<br>By installing you accept licenses for the packages.<br>Progress: Downloading terraform 0.12.6... 100%</pre><pre>terraform v0.12.6 [Approved]<br>Downloading terraform 64 bit<br>  from &#39;https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_windows<br>Download of terraform_0.12.6_windows_amd64.zip (15.32 MB) completed.<br>--SNIP--</pre><h3>The other way</h3><p>Try this method Windows for Linux Subsystem. This allows you to run Linux commands on Windows &amp; if you want make separate test environment .</p><ol><li>Install WSL through Microsoft Store, Search Ubuntu &amp; install latest one.</li></ol><p>2. In your WSL shell, run apt-get install unzip You’ll need this to extract the Terraform binaries later.</p><p>3. Download Terraform by running wget https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_linux_amd64.zip. Remember to replace the version and architecture with the one that best fits your device. You can find the full list of Terraform Releases <a href="https://releases.hashicorp.com/terraform/">here</a>.</p><p>4. Run unzip terraform_0.12.6_linux_amd64.zip terraform to unzip the contents of the zip into a folder called <em>terraform</em>.</p><p>5. Once the ZIP file is uncompressed, you’ll need to move it somewhere accessible by the system path. Fortunately, Linux has a folder that users can add binaries to by default. Move the Terraform binary there by running mv terraform /usr/local/bin/. The <em>/usr/local/bin</em> folder is already set in your system path.</p><p>6. Verify the installation was successful by running</p><pre><strong>$ terraform version</strong></pre><pre>Terraform v0.14.3<br>+ provider registry.terraform.io/hashicorp/aws v3.21.0.</pre><pre>Note:If you are using WSL also use this command to generate private key<br><strong>$ ssh-keygen</strong><br><strong>$ cat .ssh/id_rsa       &lt;-- to make sure your key exist in that path</strong></pre><pre>-----BEGIN OPENSSH PRIVATE KEY-----<br>b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gt<br>.<br>.<br>.<br>-----END OPENSSH PRIVATE KEY-----</pre><h3>Installing Python3 and Boto3</h3><p>Though you may have Python2 preinstalled in your system. It is, however, preferred to install latest version of Python3 for this project</p><p>For detailed installation, please visit <a href="https://cloudaffaire.com/how-to-install-python-boto3-sdk-for-aws/"><strong>here</strong></a></p><p>Make sure you do check installation after installing</p><pre><strong>$pip install boto3</strong><br>python3 --version<br>Python 3.9.4</pre><pre><strong>pip3 --version   </strong><br>pip 20.2.3 from C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1264.0_x64__qbz5n2kfra8p0\lib\site-packages\pip (python 3.9)</pre><pre><strong>pip3 show boto3</strong><br>Name: boto3<br>Version: 1.17.62<br>Summary: The AWS SDK for Python<br>Home-page: <a href="https://github.com/boto/boto3">https://github.com/boto/boto3</a><br>Author: Amazon Web Services<br>Author-email: None<br>License: Apache License 2.0<br>Location: c:\users\msun_\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages<br>Requires: s3transfer, jmespath, botocore<br>Required-by:</pre><h3>Boto3 to provision our VPC</h3><p>It’s time to Create a Python file using Python &amp; execute our first Boto3 script to deploy the resources in AWS.</p><p>First create a folder and switch to it</p><pre><strong>$ mkdir Boto3forVPC &amp;&amp; cd Boto3forVPC/</strong></pre><p>vim vpc.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f30aafafad5bc3068777da6aa2dcc621/href">https://medium.com/media/f30aafafad5bc3068777da6aa2dcc621/href</a></iframe><p>Run the following script to deploy the desired resources on AWS.</p><pre>$ <strong>python3 vpc.py</strong><br>ec2.Vpc(id=&#39;vpc-005382a4c773378a7&#39;)<br>[ec2.Tag(resource_id=&#39;vpc-005382a4c773378a7&#39;, key=&#39;Name&#39;, value=&#39;boto3_vpc&#39;)]<br>ec2.InternetGateway(id=&#39;igw-0e1ca1c17c56dea96&#39;)<br>ec2.RouteTable(id=&#39;rtb-0b0b2afb80ba70677&#39;)<br>ec2.Route(route_table_id=&#39;rtb-0b0b2afb80ba70677&#39;, destination_cidr_block=&#39;0.0.0.0/0&#39;)<br>ec2.Subnet(id=&#39;subnet-0b3fcb0b24adadd8b&#39;)<br>ec2.SecurityGroup(id=&#39;sg-03090bf8dcd216d50&#39;)<br>[ec2.Instance(id=&#39;i-0db6a00626adcd7d7&#39;)]</pre><p>After few minutes cross check in AWS console</p><p>Bastian Host- Ec2, VPC named boto3_vpc , InternetGateway attached to it &amp; Subnet associated with, route table (with public route)are also created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmHrV_K20hn_d-b2WjEQwQ.jpeg" /></figure><p>Security group and allow SSH inbound rule through the VPC via your own ip address (<strong><em>Notes:</em></strong> for your own security, you should<strong> never expose your ip address</strong>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLV9Ja4tktYaGLmdxGUPyw.jpeg" /></figure><p>Create a file to store the key locally and Call the boto3 ec2 function to create a key pair named ec2-keypair , then capture the key and store it in a file ec2-keypair.pem</p><pre>$ ls <br><strong>ec2-keypair.pem</strong>  vpc.py</pre><pre>Its time to destroy the resources we have just created using vim vpc_destroy.py &amp; copy the code below.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dfd87fd3b0fbb0c5af3e1f26138ec9b/href">https://medium.com/media/9dfd87fd3b0fbb0c5af3e1f26138ec9b/href</a></iframe><p>use the command below to destroy the resources we have created earlier depending on your vpc_id</p><pre>$ <strong>python3 vpc_destroy.py --vpc_id vpc-005382a4c773378a7 --region us-east-1 --services ec2</strong><br>type: &lt;class &#39;str&#39;&gt;<br>[vpc_destroy.py:243 -             &lt;module&gt;() ] calling destroy_services with ec2<br>[credentials.py:1217 -                 load() ] Found credentials in shared credentials file: ~/.aws/credentials<br>[vpc_destroy.py:58 -          destroy_ec2() ] instance deletion list: [&#39;i-0db6a00626adcd7d7&#39;]<br>[vpc_destroy.py:60 -          destroy_ec2() ] Waiting for instances to terminate<br>[vpc_destroy.py:246 -             &lt;module&gt;() ] calling delete_vpc with vpc-005382a4c773378a7<br>[vpc_destroy.py:162 -           delete_vpc() ] no ENIs remaining<br>destroyed vpc-005382a4c773378a7 in us-east-1</pre><p><strong><em>Notes: </em></strong>As shown above, you must provide <strong>vpc_id</strong>, <strong>region</strong> and <strong>services</strong>. In case you may want to learn more about how this VPC cleanup using Boto3, please refer to this <a href="https://github.com/jeffbrl/aws-vpc-destroy"><strong>post</strong></a></p><p><strong><em>Notes: </em></strong>Please make sure every time you apply vpc.py to create a brand new VPC, you need to <strong>provide with a brand new keypair name</strong>. Otherwise, creation can’t be done properly. To do so, you can use either AWS or AWS CLI</p><p>For AWS CLI, apply code below</p><pre><strong>$ aws ec2 delete-key-pair --key-name &lt;name of your key pair&gt;</strong></pre><h3>Here I also would like to provide Terraforming VPC and Terraforming VPC using AWS CloudFormation</h3><p>The reason behind it is to provide various ways to provision VPC to meet different needs and requirements. Also, let us figure out which option is more efficient and effective</p><h4><strong>Here we go with Terraforming VPC</strong></h4><p>Firstly, We need to create using vi vpc.tf file in same folder or create seperate using the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d592e1934a70f5c69a0a34224dd7b54/href">https://medium.com/media/7d592e1934a70f5c69a0a34224dd7b54/href</a></iframe><p>Secondly, you will also need to create a vi variables.tf file in order provide additional preferences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72136d3ceef89a1955f7c8bd426ed2ba/href">https://medium.com/media/72136d3ceef89a1955f7c8bd426ed2ba/href</a></iframe><p>Thirdly, you will also need to create a vi terraform.tfvars file to provide variables required</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9c51cfdbb0755e8198e71d229b0b98c/href">https://medium.com/media/c9c51cfdbb0755e8198e71d229b0b98c/href</a></iframe><p>Finally , you also need to create an <strong>vi outputs.tf</strong> file to provide outputs in the console after creation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91fe1e4e6b5f76f511ee34bb087d5b9c/href">https://medium.com/media/91fe1e4e6b5f76f511ee34bb087d5b9c/href</a></iframe><p>Now its time to terrafrom our vpc</p><pre>$ <strong>terraform init</strong></pre><p>This will initialize and install necessary plugins to make terraform run.</p><p>Makes sure to <strong>validate</strong> the syntax of the <strong>all terraform</strong> files in your directory</p><pre>$ <strong>terraform validate</strong><br>Success! The configuration is valid.</pre><p>Then, we will plan our terraform infrastructure to make sure what resources will be deployed using this code.</p><pre><strong>$ terraform plan</strong></pre><pre>Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:<br> + create</pre><pre>Terraform will perform the following actions:</pre><pre># aws_instance.bastion_host will be created<br> + resource “aws_instance” “bastion_host” {<br> + ami = “ami-0742b4e673072066f”<br> + arn = (known after apply)<br> + associate_public_ip_address = true<br> + availability_zone = (known after apply)<br> + cpu_core_count = (known after apply)<br> + cpu_threads_per_core = (known after apply)<br> + get_password_data = false<br> + host_id = (known after apply)<br> + id = (known after apply)<br> + instance_initiated_shutdown_behavior = (known after apply)<br> + instance_state = (known after apply)<br> + instance_type = “t2.micro”<br> + ipv6_address_count = (known after apply)<br> + ipv6_addresses = (known after apply)<br> + key_name = “ec2-keypair”<br> + outpost_arn = (known after apply)<br> + password_data = (known after apply)<br> + placement_group = (known after apply)<br> + primary_network_interface_id = (known after apply)<br> + private_dns = (known after apply)<br> + private_ip = (known after apply)<br> + public_dns = (known after apply)<br> + public_ip = (known after apply)<br> + secondary_private_ips = (known after apply)<br> + security_groups = (known after apply)<br> + source_dest_check = true<br> + subnet_id = (known after apply)<br> + tags_all = (known after apply)<br> + tenancy = (known after apply)<br> + vpc_security_group_ids = (known after apply)</pre><pre>+ ebs_block_device {<br> + delete_on_termination = (known after apply)<br> + device_name = (known after apply)<br> + encrypted = (known after apply)<br> + iops = (known after apply)<br> + kms_key_id = (known after apply)<br> + snapshot_id = (known after apply)<br> + tags = (known after apply)<br> + throughput = (known after apply)<br> + volume_id = (known after apply)<br> + volume_size = (known after apply)<br> + volume_type = (known after apply)<br> }</pre><pre>+ enclave_options {<br> + enabled = (known after apply)<br> }</pre><pre>+ ephemeral_block_device {<br> + device_name = (known after apply)<br> + no_device = (known after apply)<br> + virtual_name = (known after apply)<br> }</pre><pre>+ metadata_options {<br> + http_endpoint = (known after apply)<br> + http_put_response_hop_limit = (known after apply)<br> + http_tokens = (known after apply)<br> }</pre><pre>+ network_interface {<br> + delete_on_termination = (known after apply)<br> + device_index = (known after apply)<br> + network_interface_id = (known after apply)<br> }</pre><pre>+ root_block_device {<br> + delete_on_termination = (known after apply)<br> + device_name = (known after apply)<br> + encrypted = (known after apply)<br> + iops = (known after apply)<br> + kms_key_id = (known after apply)<br> + tags = (known after apply)<br> + throughput = (known after apply)<br> + volume_id = (known after apply)<br> + volume_size = (known after apply)<br> + volume_type = (known after apply)<br> }<br> }</pre><pre># aws_internet_gateway.igw will be created<br> + resource “aws_internet_gateway” “igw” {<br> + arn = (known after apply)<br> + id = (known after apply)<br> + owner_id = (known after apply)<br> + tags = {<br> + “Environment” = “Development”<br> + “Name” = “boto3_vpc”<br> }<br> + tags_all = {<br> + “Environment” = “Development”<br> + “Name” = “boto3_vpc”<br> }<br> + vpc_id = (known after apply)<br> }</pre><pre># aws_key_pair.bastion_host_key will be created<br> + resource “aws_key_pair” “bastion_host_key” {<br> + arn = (known after apply)<br> + fingerprint = (known after apply)<br> + id = (known after apply)<br> + key_name = “ec2-keypair”<br> + key_pair_id = (known after apply)<br> + public_key = (known after apply)<br> + tags_all = (known after apply)<br> }</pre><pre># aws_route_table.public_route_table will be created<br> + resource “aws_route_table” “public_route_table” {<br> + arn = (known after apply)<br> + id = (known after apply)<br> + owner_id = (known after apply)<br> + propagating_vgws = (known after apply)<br> + route = [<br> + {<br> + carrier_gateway_id = “”<br> + cidr_block = “0.0.0.0/0”<br> + destination_prefix_list_id = “”<br> + egress_only_gateway_id = “”<br> + gateway_id = (known after apply)<br> + instance_id = “”<br> + ipv6_cidr_block = “”<br> + local_gateway_id = “”<br> + nat_gateway_id = “”<br> + network_interface_id = “”<br> + transit_gateway_id = “”<br> + vpc_endpoint_id = “”<br> + vpc_peering_connection_id = “”<br> },<br> ]<br> + tags = {<br> + “Environment” = “var.environment_tag”<br> }<br> + tags_all = {<br> + “Environment” = “var.environment_tag”<br> }<br> + vpc_id = (known after apply)<br> }</pre><pre># aws_route_table_association.public_rt_association[0] will be created<br> + resource “aws_route_table_association” “public_rt_association” {<br> + id = (known after apply)<br> + route_table_id = (known after apply)<br> + subnet_id = (known after apply)<br> }</pre><pre># aws_security_group.bastion_host will be created<br> + resource “aws_security_group” “bastion_host” {<br> + arn = (known after apply)<br> + description = “Managed by Terraform”<br> + egress = [<br> + {<br> + cidr_blocks = []<br> + description = “”<br> + from_port = 22<br> + ipv6_cidr_blocks = []<br> + prefix_list_ids = []<br> + protocol = “var.protocol”<br> + security_groups = []<br> + self = false<br> + to_port = 22<br> },<br> ]<br> + id = (known after apply)<br> + ingress = [<br> + {<br> + cidr_blocks = [<br> + “72.137.76.221/32”,<br> ]<br> + description = “”<br> + from_port = 22<br> + ipv6_cidr_blocks = []<br> + prefix_list_ids = []<br> + protocol = “tcp”<br> + security_groups = []<br> + self = false<br> + to_port = 22<br> },<br> ]<br> + name = (known after apply)<br> + name_prefix = (known after apply)<br> + owner_id = (known after apply)<br> + revoke_rules_on_delete = false<br> + tags_all = (known after apply)<br> + vpc_id = (known after apply)<br> }</pre><pre># aws_subnet.public_subnet[0] will be created<br> + resource “aws_subnet” “public_subnet” {<br> + arn = (known after apply)<br> + assign_ipv6_address_on_creation = false<br> + availability_zone = “us-east-1a”<br> + availability_zone_id = (known after apply)<br> + cidr_block = “172.16.1.0/24”<br> + id = (known after apply)<br> + ipv6_cidr_block_association_id = (known after apply)<br> + map_public_ip_on_launch = false<br> + owner_id = (known after apply)<br> + tags = {<br> + “Environment” = “var.environment_tag”<br> }<br> + tags_all = {<br> + “Environment” = “var.environment_tag”<br> }<br> + vpc_id = (known after apply)<br> }</pre><pre># aws_vpc.main will be created<br> + resource “aws_vpc” “main” {<br> + arn = (known after apply)<br> + assign_generated_ipv6_cidr_block = false<br> + cidr_block = “172.16.0.0/16”<br> + default_network_acl_id = (known after apply)<br> + default_route_table_id = (known after apply)<br> + default_security_group_id = (known after apply)<br> + dhcp_options_id = (known after apply)<br> + enable_classiclink = (known after apply)<br> + enable_classiclink_dns_support = (known after apply)<br> + enable_dns_hostnames = true<br> + enable_dns_support = true<br> + id = (known after apply)<br> + instance_tenancy = “default”<br> + ipv6_association_id = (known after apply)<br> + ipv6_cidr_block = (known after apply)<br> + main_route_table_id = (known after apply)<br> + owner_id = (known after apply)<br> + tags = {<br> + “Environment” = “Development”<br> + “Name” = “boto3_vpc”<br> }<br> + tags_all = {<br> + “Environment” = “Development”<br> + “Name” = “boto3_vpc”<br> }<br> }</pre><pre># tls_private_key.public_key will be created<br> + resource “tls_private_key” “public_key” {<br> + algorithm = “RSA”<br> + ecdsa_curve = “P224”<br> + id = (known after apply)<br> + private_key_pem = (sensitive value)<br> + public_key_fingerprint_md5 = (known after apply)<br> + public_key_openssh = (known after apply)<br> + public_key_pem = (known after apply)<br> + rsa_bits = 4096<br> }</pre><pre>Plan: 9 to add, 0 to change, 0 to destroy.</pre><pre>Changes to Outputs:<br> + cidr_block = “172.16.0.0/16”<br> + gateway_id = (known after apply)<br> + key_name = “ec2-keypair”<br> + route_table_id = (known after apply)<br> + subnet_id = (known after apply)<br> + tags = {<br> + Environment = “Development”<br> }<br> + vpc_security_group_ids = [<br> + (known after apply),<br> ]</pre><p>Once you are ready, lets provision the infrastructure using the command below.</p><pre><strong>$ terraform apply --auto-approve</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*SWwx2Xy_GQim6ZEDl4oyCA.jpeg" /><figcaption>creation complete</figcaption></figure><p>Then lets double check our resources which have been created in AWS console</p><p>VPC named boto3_vpc created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmHrV_K20hn_d-b2WjEQwQ.jpeg" /><figcaption>VPC named boto3_vpc</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BusNYL8i7xZqrTcjBNtWSg.jpeg" /><figcaption>Subnet and associate it with route table</figcaption></figure><p><strong>Its time to clear up infrastructure we have created using Terraform</strong></p><pre>$ <strong>terraform destroy</strong><br>.<br>.<br>   Enter a value: yes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*YKU9GlWyCDqzTu3lLKlh8Q.jpeg" /><figcaption>terraform destroy vpc.tf</figcaption></figure><h3>Now we will provision VPC using CloudFormation</h3><p>Here is the AWS official <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/cloudformation-vpc-template.html"><strong>template</strong></a><strong> </strong>for VPC as reference</p><p><strong><em>Note:</em></strong><em> First create a key-pair as CloudFormation cannot create it. You will need it to access EC2 instances.</em></p><pre>$ <strong>aws ec2 create-key-pair --key-name ec2-keypair</strong><br>{<br>    &quot;KeyFingerprint&quot;: &quot;ab:b2:0c:81:9e:1e:07:d5:15:bb:a9:b1:41:b0:5d:e2:af:b5:38:23&quot;,<br>    &quot;KeyMaterial&quot;: &quot;-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAmB0Ani+OiUMiqrlgrMc50oGo9KjsVj3MNnxbmFSyMNxuLrSp\nXLiRsSHcJK7cH6IxOXuSOE0fczJmhFQZnFLTpkOqx7ELpRBDSTFdnYfqXf5oxrjs\nf5OZRXuZqjncgxxd7f/KLEBrn5xBR03aiUkc/w5lYTR0JMjWIlIsPxIxRwF9NZ/o\n2AA6K/gX2lqteFV9mUizq0Z301Ryd/RNyeABEHhJ4fuJTb1MlBc1wEGZj2pM0aVr\n67nRV0RZhTP8uj9MKg1OAvb5yaZuvBiccoiUOshoYjgrPJsnuywH6kNLHNahbrjj\n9XirKQdQ4TogqJnaW/Vd3d9J8IwNA8LcYs88owIDAQABAoIBACxeaUu6u2y2NGpv\n4A8FnYwVXd7fVvBg3iwWYfEw4zj1Uv40nCH7hCOSqM/aYUKo4IrPzHq3pDDJxrVa\ngo3iavHYUvwkXC0tbTLwP0ov1uDL0GwGjJU5zD9EKjJI5lUn9Q3yylnWAI5x2Wif\nANuCg/6xiEiuMCJ6olsodNeAyvbWuIhR+uyFfVE4vEdoqK4l8UYWQNACOnppKgaJ\nrbcKnfi+dj0AejQInpk8Ov6UUdTEINQZ4JG/d/2DFYWktGBmHVhEm9h4WIr9HRV6\nQT6LklIZYF6e9W379Z5ZXX1aGUdSeHPAefFkNwPrNCMjLCRur+C16dUAzO6jBRpG\nYZPcauECgYEA3F/9ioQ0x4//wAQkzZb81tFqRRjKTSggx2+lTKkb/UhXtCN67XJD\nMzJoGOIVPVbHdcmpP0v0cG7g71e0gyRZ7zN0m28n6L415UXOx2/PL3qZoRb3TcAq\njm4uaTxp0pCXLRmfryqiCcZzu6cmxG6YujmtKNdBrGjuvIqNdZCutu8CgYEAsLQR\nNcvxBxAGFwSWZv5ztf5agmpgK8j9gVxcO3Qc0QIU67o78hgvVkNhYgopWt4UmKzi\nPRMMVRwX82iNpLFXwqgKQnIcueYiYXdC8F9+FSByq1TnkTFtLQJwJlRln0/TreNO\n6XN+gZBmldacExyqPAz93+vZo4lvu1LcbXybNY0CgYAkPf0afKeZcksjLwtGbGBk\ni8goWO1cRw8s/WV3+A/MVctmqrcaucHnd5C7FuNbVRw0eNfGux0WKIYBlrDvKFlK\nB3JT5bHwiueeLx7UmcS/EDCX14kQVlwpVGF5mR/mKzVRi3dBfYdsiCCcad7sSyv+\n5GFf6Ba63f71LuwYu5SgLQKBgQCTxzQxcorz5iHBtFN4dUseJEdblE0zsRbZzf1Q\nt421+nC2p/ykPjewhA94Z5koZlyBRuy6OSjyMNmS9pim6K3FnLVf1oFRszaDnrL7\nxlDyqD1eLlavpc9xef2DAMgwURlt7pE7Shy9jJ9OprnGfg2cxRy43U0ZqMIpvmWc\npz5CrQKBgCttNZrapWuh8Y6QXlMDp5sCovUAj9Fw5J11j0yZyf+i704hnEuv+/5H\nvzFuvTwaRlSIoz1Frnvhb9NF+9NYqrno2T3GOATRgThgHKN9soqJism5tG/jLGDS\n2x9P99HC94Ybd13IKDXrLK/gCVh97Zlel21CY2+Pu6K/6L3kjogH\n-----END RSA PRIVATE KEY-----&quot;,<br>    &quot;KeyName&quot;: &quot;ec2-keypair&quot;,<br>    &quot;KeyPairId&quot;: &quot;key-023bd02d2f97b4a31&quot;<br>}<br></pre><p>After creating key-pair, its time to create stack using AWS-CLI with CloudFormation &amp; code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66ae3da22fd05c5897133c693de6229a/href">https://medium.com/media/66ae3da22fd05c5897133c693de6229a/href</a></iframe><p>Using the following code you can deploy similar resources on CloudFormation</p><pre><strong>$ aws cloudformation create-stack — stack-name cfvpc — template-body file://vpc.yaml</strong><br>StackId: arn:aws:cloudformation:us-east-1:050411548990:stack/cfvpc/56c90c50-ab72–11eb-b620–0adbfd4180bb</pre><p>Then we will cross check our resources in AWS console &gt;&gt;CloudFormation in Resources Tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qguFqqCiI5oEsImuJRqpaQ.jpeg" /></figure><p>You can verify all the resources here and click on the resources to go their direct location where they are created, the benefit of CloudFormation where you can check, edit &amp; destroy resources within AWS.</p><p><strong><em>Notes:</em></strong> Using CloudFormation, we will also be able to print out Outputs for reference in the future</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rAkYzqvsLKKQ86NI.png" /></figure><p><strong>Parameters</strong></p><p><strong><em>Notes: </em></strong>Parameters allow us to record the parameters we input initially</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*0tnu7u5e-nVbqvUz.png" /></figure><h4><strong>Template</strong></h4><p><strong><em>Note: </em></strong>We are able to store an original CloudFormation template file as a backup in this section</p><p>Now it’s time for us to clean up &amp; delete the infrastructure.</p><pre><strong>aws cloudformation delete-stack --stack-name cfvpc</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HlVQgsoF-edA2GpoL5UFw.jpeg" /></figure><p>It is all cleaned up now.</p><h4>Take advantage of Terraform and CloudFormation to accomplish Terraforming CloudFormation to provision VPC</h4><p>To do this project, we will need to create a brand new directory and change into it</p><pre>$ mkdir tf_cf_vpc &amp;&amp; cd tf_cf_vpc/</pre><p>For the CloudFormation, we still will be using our <a href="https://gist.github.com/mynameisameed/f6dc49f60ccbed0ea90f0d6df48dd954">vpc.yaml</a> file created previously.</p><p>We also need to create our <strong>tf_cf_vpc.tf</strong> file using code below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9e7a49b0731e7da98bc47939b9cbbe9/href">https://medium.com/media/e9e7a49b0731e7da98bc47939b9cbbe9/href</a></iframe><p>Finally we are ready to terraform our infrastructure using IaC both tools.</p><pre>$ <strong>terraform init</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*Nr_o2mcnG7cD4DptzZ_b4A.png" /></figure><p>Then validate our code:</p><pre>$ <strong>terraform validate</strong><br>Success! The configuration is valid.</pre><p>After that, lets plan our infrastructure &amp; make sure of your desired resources:</p><pre><strong>$ terraform plan</strong></pre><pre>Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:<br> + create</pre><pre>Terraform will perform the following actions:</pre><pre># aws_cloudformation_stack.tf_cf_vpc will be created<br> + resource “aws_cloudformation_stack” “tf_cf_vpc” {<br> + id = (known after apply)<br> + name = “TfCfVpc”<br> + outputs = (known after apply)<br> + parameters = {<br> + “InstanceType” = “t3.nano”<br> + “KeyName” = “tf_cf_keypair”<br> }<br> + policy_body = (known after apply)<br> + tags_all = (known after apply)<br> + template_body = &lt;&lt;-EOT<br> Description: This CloudFormation YAML file will provision a VPC</pre><pre>Parameters:<br> KeyName:<br> Description: Name of an existing EC2 KeyPair to enable SSH access to the instance<br> Type: AWS::EC2::KeyPair::KeyName<br> Default: ec2-keypair</pre><pre>InstanceType:<br> Description: EC2 instance type<br> Type: String<br> Default: t2.micro</pre><pre>EnvironmentName:<br> Description: An environment name that is prefixed to resource names<br> Type: String<br> Default: Development</pre><pre>VpcCIDR:<br> Description: Please enter the IP range (CIDR notation) for this VPC<br> Type: String<br> Default: “172.16.0.0/16”</pre><pre>PublicSubnet1CIDR:<br> Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone<br> Type: String<br> Default: “172.16.1.0/24”</pre><pre>Mappings:<br> AWSRegionToAMI:<br> us-east-1:<br> AMIID: ami-0742b4e673072066f</pre><pre>Resources:<br> VPC:<br> Type: AWS::EC2::VPC<br> Properties:<br> CidrBlock:<br> Ref: VpcCIDR<br> EnableDnsSupport: true<br> EnableDnsHostnames: true<br> Tags:<br> — Key: Name<br> Value:<br> Ref: EnvironmentName</pre><pre>InternetGateway:<br> Type: AWS::EC2::InternetGateway<br> Properties:<br> Tags:<br> — Key: Name<br> Value:<br> Ref: EnvironmentName</pre><pre>InternetGatewayAttachment:<br> Type: AWS::EC2::VPCGatewayAttachment<br> Properties:<br> InternetGatewayId:<br> Ref: InternetGateway<br> VpcId:<br> Ref: VPC</pre><pre>PublicSubnet1:<br> Type: AWS::EC2::Subnet<br> Properties:<br> VpcId:<br> Ref: VPC<br> AvailabilityZone: !Select [ 0, !GetAZs ‘’ ]<br> CidrBlock:<br> Ref: PublicSubnet1CIDR<br> MapPublicIpOnLaunch: true<br> Tags:<br> — Key: Name<br> Value: !Sub ${EnvironmentName} Public Subnet (AZ1)</pre><pre>PublicRouteTable:<br> Type: AWS::EC2::RouteTable<br> Properties:<br> VpcId:<br> Ref: VPC<br> Tags:<br> — Key: Name<br> Value: !Sub ${EnvironmentName} Public Routes</pre><pre>DefaultPublicRoute:<br> Type: AWS::EC2::Route<br> DependsOn: InternetGatewayAttachment<br> Properties:<br> RouteTableId:<br> Ref: PublicRouteTable<br> DestinationCidrBlock: 0.0.0.0/0<br> GatewayId:<br> Ref: InternetGateway</pre><pre>PublicSubnet1RouteTableAssociation:<br> Type: AWS::EC2::SubnetRouteTableAssociation<br> Properties:<br> RouteTableId:<br> Ref: PublicRouteTable<br> SubnetId:<br> Ref: PublicSubnet1</pre><pre>VPCEC2SecurityGroup:<br> Type: AWS::EC2::SecurityGroup<br> Properties:<br> GroupDescription: only allow SSH traffic<br> GroupName: SSH-ONLY<br> SecurityGroupIngress:<br> — CidrIp: 72.137.76.221/32<br> FromPort: 22<br> IpProtocol: tcp<br> ToPort: 22<br> Tags:<br> -<br> Key: Name<br> Value: CloudFormationSecurityGroup<br> VpcId:<br> Ref: VPC</pre><pre>VPCEC2:<br> Type: AWS::EC2::Instance<br> Properties:<br> ImageId:<br> !FindInMap<br> — AWSRegionToAMI<br> — !Ref AWS::Region<br> — AMIID<br> InstanceType: !Ref InstanceType<br> SecurityGroupIds:<br> — !GetAtt “VPCEC2SecurityGroup.GroupId”<br> SubnetId: !Ref PublicSubnet1<br> KeyName:<br> Ref: KeyName</pre><pre>Outputs:<br> VPC:<br> Description: A reference to the created VPC<br> Value:<br> Ref: VPC</pre><pre>PublicSubnet1:<br> Description: A reference to the public subnet in the 1st Availability Zone<br> Value:<br> Ref: PublicSubnet1</pre><pre>VPCEC2SecurityGroup:<br> Description: Security group with no ingress rule<br> Value:<br> Ref: VPCEC2SecurityGroup</pre><pre>InternetGateway:<br> Description: InternetGateway Information<br> Value:<br> Ref: InternetGateway</pre><pre>PublicRouteTable:<br> Description: Public Route Table Information<br> Value:<br> Ref: PublicRouteTable</pre><pre>VPCEC2:<br> Description: EC2 Information<br> Value:<br> Ref: VPCEC2<br> EOT<br> }</pre><pre># aws_key_pair.bastion_host_key will be created<br> + resource “aws_key_pair” “bastion_host_key” {<br> + arn = (known after apply)<br> + fingerprint = (known after apply)<br> + id = (known after apply)<br> + key_name = “tf_cf_keypair”<br> + key_pair_id = (known after apply)<br> + public_key = (known after apply)<br> + tags_all = (known after apply)<br> }</pre><pre># tls_private_key.public_key will be created<br> + resource “tls_private_key” “public_key” {<br> + algorithm = “RSA”<br> + ecdsa_curve = “P224”<br> + id = (known after apply)<br> + private_key_pem = (sensitive value)<br> + public_key_fingerprint_md5 = (known after apply)<br> + public_key_openssh = (known after apply)<br> + public_key_pem = (known after apply)<br> + rsa_bits = 4096<br> }</pre><pre>Plan: 3 to add, 0 to change, 0 to destroy.</pre><pre>────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────</pre><pre>Note: You didn’t use the -out option to save this plan, so Terraform can’t guarantee to take exactly these actions if you run “terraform apply” now.<br>Then run the following to deploy resources in AWS</pre><pre><strong>$ terraform apply  --auto-approve</strong></pre><p>Then we will verify &amp; double check the resources created in AWS console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*czks6VUFE1HPL9EK.png" /><figcaption>VPC named Development created</figcaption></figure><p>IGW created, which is attached to Development</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RCtEhjVj_x1StLz4.png" /><figcaption>IGW created, which is attached to Development</figcaption></figure><h4><strong>InternetGateway</strong></h4><p>Subnet and associate it with route table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vJZxqEwN9ggOuB8g.png" /></figure><h4><strong>Subnet with route table</strong></h4><p>Route table with a public route</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OZHokbNTY995Qbas.png" /></figure><h4><strong>Route table with public route</strong></h4><p>Security group and allow SSH inbound rule through the VPC via your own ip address (<strong><em>Notes:</em></strong> for your own security, you should<strong> never expose your ip address</strong>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kv6vtUeXjw1VhhIN.png" /></figure><p>SSH with your own ip address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gyizUk10RlK196EZ.png" /></figure><p>EC2 is now created!</p><p><strong><em>Note:</em></strong> Here we will be updating one <strong>InstanceType </strong>value in our .tf file and test the power of terraform. Along with CloudFormation, we can take advantage of both Terraform’s flexibility and CloudFormation’s AWS native and easy provision</p><p>Here we will make update <strong>tf_cf_vpc.tf </strong>file &amp; change the InstanceType from <strong>t2.micro</strong> &gt;&gt; to <strong>t3.large</strong></p><p>Let us plan it again to see the difference:</p><pre><strong>$ terraform plan</strong></pre><pre>Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:<br> + create</pre><pre>Terraform will perform the following actions:</pre><pre># aws_cloudformation_stack.tf_cf_vpc will be created<br> + resource “aws_cloudformation_stack” “tf_cf_vpc” {<br> + id = (known after apply)<br> + name = “TfCfVpc”<br> + outputs = (known after apply)<br> + parameters = {<br> + “InstanceType” = “t3.large”<br> + “KeyName” = “tf_cf_keypair”<br> }<br> + policy_body = (known after apply)<br> + tags_all = (known after apply)<br> + template_body = &lt;&lt;-EOT<br> Description: This CloudFormation YAML file will provision a VPC</pre><pre>Parameters:<br> KeyName:<br> Description: Name of an existing EC2 KeyPair to enable SSH access to the instance<br> Type: AWS::EC2::KeyPair::KeyName<br> Default: ec2-keypair</pre><pre>InstanceType:<br> Description: EC2 instance type<br> Type: String<br> Default: t2.micro</pre><pre>EnvironmentName:<br> Description: An environment name that is prefixed to resource names<br> Type: String<br> Default: Development</pre><pre>VpcCIDR:<br> Description: Please enter the IP range (CIDR notation) for this VPC<br> Type: String<br> Default: “172.16.0.0/16”</pre><pre>PublicSubnet1CIDR:<br> Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone<br> Type: String<br> Default: “172.16.1.0/24”</pre><pre>Mappings:<br> AWSRegionToAMI:<br> us-east-1:<br> AMIID: ami-0742b4e673072066f</pre><pre>Resources:<br> VPC:<br> Type: AWS::EC2::VPC<br> Properties:<br> CidrBlock:<br> Ref: VpcCIDR<br> EnableDnsSupport: true<br> EnableDnsHostnames: true<br> Tags:<br> — Key: Name<br> Value:<br> Ref: EnvironmentName</pre><pre>InternetGateway:<br> Type: AWS::EC2::InternetGateway<br> Properties:<br> Tags:<br> — Key: Name<br> Value:<br> Ref: EnvironmentName</pre><pre>InternetGatewayAttachment:<br> Type: AWS::EC2::VPCGatewayAttachment<br> Properties:<br> InternetGatewayId:<br> Ref: InternetGateway<br> VpcId:<br> Ref: VPC</pre><pre>PublicSubnet1:<br> Type: AWS::EC2::Subnet<br> Properties:<br> VpcId:<br> Ref: VPC<br> AvailabilityZone: !Select [ 0, !GetAZs ‘’ ]<br> CidrBlock:<br> Ref: PublicSubnet1CIDR<br> MapPublicIpOnLaunch: true<br> Tags:<br> — Key: Name<br> Value: !Sub ${EnvironmentName} Public Subnet (AZ1)</pre><pre>PublicRouteTable:<br> Type: AWS::EC2::RouteTable<br> Properties:<br> VpcId:<br> Ref: VPC<br> Tags:<br> — Key: Name<br> Value: !Sub ${EnvironmentName} Public Routes</pre><pre>DefaultPublicRoute:<br> Type: AWS::EC2::Route<br> DependsOn: InternetGatewayAttachment<br> Properties:<br> RouteTableId:<br> Ref: PublicRouteTable<br> DestinationCidrBlock: 0.0.0.0/0<br> GatewayId:<br> Ref: InternetGateway</pre><pre>PublicSubnet1RouteTableAssociation:<br> Type: AWS::EC2::SubnetRouteTableAssociation<br> Properties:<br> RouteTableId:<br> Ref: PublicRouteTable<br> SubnetId:<br> Ref: PublicSubnet1</pre><pre>VPCEC2SecurityGroup:<br> Type: AWS::EC2::SecurityGroup<br> Properties:<br> GroupDescription: only allow SSH traffic<br> GroupName: SSH-ONLY<br> SecurityGroupIngress:<br> — CidrIp: 72.137.76.221/32<br> FromPort: 22<br> IpProtocol: tcp<br> ToPort: 22<br> Tags:<br> -<br> Key: Name<br> Value: CloudFormationSecurityGroup<br> VpcId:<br> Ref: VPC</pre><pre>VPCEC2:<br> Type: AWS::EC2::Instance<br> Properties:<br> ImageId:<br> !FindInMap<br> — AWSRegionToAMI<br> — !Ref AWS::Region<br> — AMIID<br> InstanceType: !Ref InstanceType<br> SecurityGroupIds:<br> — !GetAtt “VPCEC2SecurityGroup.GroupId”<br> SubnetId: !Ref PublicSubnet1<br> KeyName:<br> Ref: KeyName</pre><pre>Outputs:<br> VPC:<br> Description: A reference to the created VPC<br> Value:<br> Ref: VPC</pre><pre>PublicSubnet1:<br> Description: A reference to the public subnet in the 1st Availability Zone<br> Value:<br> Ref: PublicSubnet1</pre><pre>VPCEC2SecurityGroup:<br> Description: Security group with no ingress rule<br> Value:<br> Ref: VPCEC2SecurityGroup</pre><pre>InternetGateway:<br> Description: InternetGateway Information<br> Value:<br> Ref: InternetGateway</pre><pre>PublicRouteTable:<br> Description: Public Route Table Information<br> Value:<br> Ref: PublicRouteTable</pre><pre>VPCEC2:<br> Description: EC2 Information<br> Value:<br> Ref: VPCEC2<br> EOT<br> }</pre><pre># aws_key_pair.bastion_host_key will be created<br> + resource “aws_key_pair” “bastion_host_key” {<br> + arn = (known after apply)<br> + fingerprint = (known after apply)<br> + id = (known after apply)<br> + key_name = “tf_cf_keypair”<br> + key_pair_id = (known after apply)<br> + public_key = (known after apply)<br> + tags_all = (known after apply)<br> }</pre><pre># tls_private_key.public_key will be created<br> + resource “tls_private_key” “public_key” {<br> + algorithm = “RSA”<br> + ecdsa_curve = “P224”<br> + id = (known after apply)<br> + private_key_pem = (sensitive value)<br> + public_key_fingerprint_md5 = (known after apply)<br> + public_key_openssh = (known after apply)<br> + public_key_pem = (known after apply)<br> + rsa_bits = 4096<br> }</pre><pre>Plan: 3 to add, 0 to change, 0 to destroy.</pre><pre>────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────</pre><pre>Note: You didn’t use the -out option to save this plan, so Terraform can’t guarantee to take exactly these actions if you run “terraform apply” now.</pre><p>It’s time to reapply to update your instance_type changes which takes less time:</p><pre>$ <strong>terraform apply</strong><br>.<br>.<br>.<br> Enter a value: yesaws_cloudformation_stack.tf_cf_vpc: Modifying... [id=arn:aws:cloudformation:us-east-1:464392538707:stack/TfCfVpc/b8b5f360-a4b5-11eb-b4b0-12d101416601]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 10s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 20s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 30s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 40s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 50s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 1m0s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 1m10s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 1m20s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Still modifying... [id=arn:aws:cloudformation:us-east-1:464392...c/b8b5f360-a4b5-11eb-b4b0-12d101416601, 1m30s elapsed]<br>aws_cloudformation_stack.tf_cf_vpc: Modifications complete after 1m39s [id=arn:aws:cloudformation:us-east-1:464392538707:stack/TfCfVpc/b8b5f360-a4b5-11eb-b4b0-12d101416601]Apply complete! Resources: 0 added, 1 changed, 0 destroyed.</pre><p>Let us double check in AWS console in EC2 instances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kU9xA9iM4LQ4bdYY.png" /></figure><p>Now let’s destroy the whole infrastructure one last time:</p><pre><strong>$ terraform destroy — auto-approve</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*V4jFh1qxSo76RfS6XKbhYA.png" /><figcaption>destroyed <strong>tf_cf_vpc.tf</strong></figcaption></figure><h3>Summary</h3><p>Let us recap our project’s objective and what we have accomplished</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*nsWKzODslnKeJChc.png" /></figure><h4><strong>Project Architecture</strong></h4><p>As shown from project architecture, we dive into 4 different ways to provision VPC using Infra-as-code tools.</p><ul><li>Boto3</li><li>CloudFormation (AWS native)</li><li>Terraform (Cloud native)</li><li>Terraform + CloudFormation</li></ul><p>First of all, <strong>using Boto3</strong>, it may require 2 different files to create vpc in the first place and destroy it at the end of the day. With that said, it could be a concern in terms of management</p><p>Secondly, we built up our VPC infrastructure<strong> using CloudFormation</strong>. Since it is AWS native, it did work perfectly. However, in terms of updates, we may need to work on the same file for parameters as per say. But it could still be well managed.</p><p>Thirdly, <strong>Terraform as IaC tool did shine with its flexibility</strong>. From building infrastructure, through updating to destroying at the end of the day, every single move was seamless. However, we need to spend time building infrastructure using Terraform as a brand new language. With that said, it could be time-consuming.</p><p>Finally, my preference way: <strong>Terraform + CloudFormation</strong> for AWS. Taking advantage of every aspect of Terraform, we advance our AWS infrastructure using CloudFormation. Templates were readily available on AWS official website and plenty of cloud related blogs and websites. We can simply apply the CloudFormation .yaml file with Terraform.</p><p>More importantly, Terraform’s flexibility still applies. For instance, in project, we update our <strong>InstanceType </strong>using a parameters in .tf file. This infrastructure for AWS is best of both worlds (or maybe three)</p><p><strong>Terraform + Cloud Native IaC Tool for your Cloud provider </strong>should be the way to go in Cloud!</p><p>I will be making more projects on migrations specifically using Terraform|GCP|AWS|Ansible|Python| more.</p><p>Thank you for reading! Please do let me know your thoughts in the comments, and feel free to share if you have found this useful.</p><p>Feel free to connect with me on <a href="https://www.linkedin.com/in/mynameisameed/">Linkedin</a> if you are facing any issues with this.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af741a8afb3c" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/creating-vpc-using-boto3-terraform-cloudformation-and-both-af741a8afb3c">Deploy AWS resources with Boto3, Terraform, and CloudFormation</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup Ansible on Windows using Visual Studio Code + AWS, Web Servers + LoadBalancer &…]]></title>
            <link>https://msameeduddin.medium.com/how-to-setup-ansible-on-windows-using-visual-studio-code-aws-web-servers-loadbalancer-8dba17c9fa64?source=rss-80f402b00930------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dba17c9fa64</guid>
            <category><![CDATA[automation-tools]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sameed Uddin]]></dc:creator>
            <pubDate>Mon, 19 Apr 2021 19:43:42 GMT</pubDate>
            <atom:updated>2021-06-28T10:28:37.627Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Setup Ansible on Windows &amp; Deploy Web Server on AWS</h3><p>Ansible is an simple agentless + configuration management + automation that automates deployment, + orchestration. Ansible is popularity due to it’s simplicity for being opensource, agentless, efficient, requires no additional software installed on target machine, It use the simple YAML .(which stands for “YAML Ain’t Markup Language”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/0*6DusbfT0Bwxoghga" /></figure><p>Ansible architecture is very simple. It requires Ansible Controller basically a node either a laptop, PC or server where Ansible is installed with the module of configuration files called <strong>playbook</strong> (like a recipe book) and inventory of target servers called <strong>hosts</strong>. Playbook consists of Roles, and Roles consists of Tasks. Task is an individual command in Ansible. By using inventory we group the nodes by using labels.</p><p>Ansible Server and the node talks by using SSH.</p><p>Steps to work with Ansible:</p><ol><li>If you are using Linux skip this step if not use this <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">link</a> to install Ubuntu VM on your Windows 10 &amp; also install <a href="https://code.visualstudio.com/download">Visual Studio Code</a>.</li><li>Create playbook and inventory in local machine</li><li>Create SSH to the target nodes</li><li>Ansible Server gathers the facts of the target nodes to get the indication of the target nodes</li><li>Playbook are sent to nodes</li><li>Playbook are executed in the nodes</li></ol><h3>What is-</h3><p><strong>Ansible Server or Controller:</strong> The machine where Ansible is installed and from which all tasks and playbooks will be ran.<br><strong>Module:</strong> Basically, a module is a command or set of similar commands meant to be executed on the client-side.<br><strong>Task: </strong>A task is a section that consists of a single procedure to be completed.<br><strong>Role:</strong> A way of organizing tasks and related files to be later called in a playbook<br><strong>Fact: </strong>Information fetched from the client system from the global variables with the gather-facts operation.<br><strong>Inventory:</strong> File containing data about the ansible client servers which can be defined in later examples as hosts file.<br><strong>Play: </strong>Execution of a playbook.<br><strong>Handler:</strong> Task which is called only if a notifier is present.<br><strong>Notifier: </strong>Section attributed to a task which calls a handler if the output is changed.<br><strong>Tag: </strong>Name set to a task which can be used later on to issue just that specific task or group of tasks.</p><p><strong>Prerequisites for Installing Ansible:</strong></p><ol><li>The control machine that we will run Ansible commands from.</li><li>Preferably Linux/Unix based.</li><li>You can also setup using <a href="https://docs.ansible.com/ansible/2.4/guide_vagrant.html">Vagrant </a>box or <a href="https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04">Docker </a>.</li><li>You will need Python 2.x or 3.x installed.</li><li>Documentation for Installing Control Machine <a href="https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-the-control-machine">here</a>.</li></ol><p><strong>Resources you will need to follow along this basic Ansible Lab:</strong></p><ul><li>Windows or Linux Setup</li><li><a href="https://aws.amazon.com/">AWS </a>(create if you dont have one , the wont charge as its comes under Free-Tier)or any of your favourite vendor specific Cloud Account.</li><li>For this lab you need 3 EC2 instances to create</li><li>To connect your ec2 instances, you need key-pair from AWS Account <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html">link</a>.</li></ul><p><strong>STEP 1: Setup Windows Subsystem for Linux</strong></p><pre><strong>(if you are using Linux :<br>$ sudo easy_install pip  &lt;--- </strong>you need to install pip first.<br><strong>$ sudo pip install ansible &lt;--- </strong>install ansible next.<strong><br>$ ansible --version        &lt;---</strong> finally make sure its installed.)</pre><ul><li>After installing <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Ubuntu WSL</a> &amp; <a href="https://code.visualstudio.com/download">Visual Studio Code</a> , Login to Ubuntu,&amp; create a user called ansible-user</li><li>Then login to <a href="https://aws.amazon.com/">AWS</a> Console and go to CloudFormation &gt; Create stack &gt; Select Upload a Template file then use this code from <a href="https://github.com/mynameisameed/Course_Introduction_to_Ansible/blob/master/02_02_Introduction_To_Ansible/setup-env.yml">Github </a>repository.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Ab--ipHHIsXTK2IIz6Ouw.png" /></figure><ul><li>Click Next &amp; Set a Stack name &amp; select a key-pair you have created from <a href="https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#KeyPairs:">here</a> (name it Ansible-keypair.pem), then click next &gt; set a tag &gt; next review and create stack.</li></ul><p><strong>STEP 2 : Install Ansible on </strong><a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10"><strong>WSL</strong></a></p><pre><strong>$ sudo apt-get update  &lt;--- </strong>update the OS packages.<br><strong>$ sudo apt-get install ansible -y &lt;--</strong> install the ansible.<strong><br>$ ansible -- version        &lt;-- </strong>make sure its installed correctly.</pre><p><strong>STEP 3: Setup SSH Connection to Target Server</strong></p><ul><li>Then log back in to your local host — open the Visual Studio Code(from Desktop) then press Ctrl + ~ which will open terminal then select default Shell as WSL Bash &amp; then use the following commands:</li></ul><p>(Make sure you can ssh to server with certificate and can ssh successfully)</p><ul><li>Create a Directory for Ansible &amp; also for ssh key-pairs.</li><li>Then change permissions on key-pair to read.</li></ul><pre><strong><br>$ mkdir /home/ansible-user/ansible/ </strong>&lt;--to keep all ansible files.<br><strong>$ cd ~     &lt;-- got go back to home directory<br>$ explorer.exe . &lt;- will open the folder, then drag it in VS Code.<br>$ ansible --version &lt;-- </strong>to check where default ansible.cfg stored, but we will create another location for easy access.<br><strong>$ mkdir .ssh/        </strong>&lt;---to store the key-pairs in hidden folder.<strong><br>$ explorer.exe .ssh  </strong>&lt;--- open the window, then drag key-pair from Downloads folder in Windows-10 which you got from AWS to .ssh <strong><br>$ chmod 400 .ssh/ansible-keypair.pem </strong>&lt;-- to give ansible read permission.<strong><br>$ ssh -i ~/.ssh/ansible-keypair.pem ec2-user@&lt;ip address of any ec2 instance&gt;   </strong>&lt;-- Test check connectivity &amp; permissions working.</pre><blockquote>Tip: Check the IP Addresses in Ouputs tab in AWS CloudFormation Stack</blockquote><p><strong>STEP 3: Setup Custom Inventory File (reference </strong><a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html"><strong>link</strong></a><strong>)</strong></p><ul><li>We need to give Ansible a reference to over inventory servers we want to execute commands on.</li><li>There are two types of inventory files- <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html">Dynamic </a>&amp; we are using Static one.</li><li>You can use either YAML or INI format.</li><li>Create a host called hosts-dev .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*ktahtNUDYvR_OSm_LMjIGw.png" /></figure><pre>#(refer AWS CloudFormation Stack Outputs tab,we have ec2 instances created earlier with same names &amp; past accordingly with their names like below)</pre><pre><strong># hosts-dev              &lt;alias&gt; &lt;hostname&gt; = ip address</strong></pre><pre><strong>[webservers]  &lt;--- group<br>app1 ansible_host=54.211.227.5 &lt;--- hostname with ip address<br>app2 ansible_host=3.211.163.3</strong></pre><pre><strong>[loadbalancers]<br>lb1 ansible_host=52.3.9.173 &lt;--- hostname with ip address</strong></pre><pre><strong>[local]<br>control ansible_connection=local</strong></pre><p>Then use the following command to use this file to list all hosts</p><pre>sameed@local:~/ansible$ <strong>ansible -i hosts-dev — list-hosts all</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*gHPvN_fqKV7agGp4_cH3_g.png" /></figure><p><strong>Step 4: Setup Configuration File (reference </strong><a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings"><strong>link</strong></a><strong>)</strong></p><ul><li>Creating a configuration file to control local Ansible Environment settings.</li><li>Use the following snippet to setup ansible.cfg &amp; key-pair path to access your ec2 instances from your AWS account which we have created earlier.</li></ul><pre><strong># ansible.cfg<br>[defaults]<br>inventory = ./hosts-dev<br>remote_user = ec2-user<br>private_key_file = ~/.ssh/ansible-course-keypair.pem<br>host_key_checking = False</strong></pre><pre><strong>#Windows only users<br>[ssh_connection]<br>ssh_args = -o ControlMaster=no</strong></pre><p><strong>Step 5: Creating &amp; Working with Playbooks (reference </strong><a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html"><strong>link</strong></a><strong>)</strong></p><ul><li>Playbooks use YAML syntax which allows you to model a configuration or a process.</li><li>Playbooks are composed of one or more plays in a list.</li><li>The goal of a play is to map a group of host (defined in inventory file) to a tasks that are used to call Ansible modules.</li><li>By composing a playbook of multiple plays, it makes it possible to orchestrate multi-machine deployments and allows us to run certain steps on all machines in a group.</li><li>to start with three dashes (---) &amp; proper indentation using spaces and <strong>not</strong> tabs!</li></ul><blockquote>Download the playbooks via github <a href="https://github.com/mynameisameed/Course_Introduction_to_Ansible/tree/master/04_05_Introduction_To_Ansible">here </a>to follow along with me(also you can download other playbooks and use for other tasks)</blockquote><p>In this example we are going to automate the simple task in Ubuntu by Updating the OS, installing different services for a Web-Server, :</p><pre>Create playbooks folder in ansible folder,then copy &amp; paste the following files individually.</pre><pre><strong># yum-update.yml<br><br>---<br>  - hosts: webservers:loadbalancers<br>    become: true<br>    tasks:<br>      - name: Updating yum packages<br>        yum: name=* state=latest<br></strong></pre><pre><strong># install-services.yml<br><br>---<br>  - hosts: loadbalancers<br>    become: true<br>    tasks:<br>      - name: Installing apache<br>        yum: name=httpd state=present<br>      - name: Ensure apache starts<br>        service: name=httpd state=started enabled=yes<br><br>  - hosts: webservers<br>    become: true<br>    tasks:<br>      - name: Installing services<br>        yum:<br>          name: <br>            - httpd<br>            - php<br>          state: present<br>      - name: Ensure apache starts<br>        service: name=httpd state=started enabled=yes</strong></pre><p>Also create a index.php file in ansible folder:</p><pre><strong>&lt;?php<br> echo &quot;&lt;h1&gt;Hello, World! This is my Ansible page.&lt;/h1&gt;&quot;;<br>?&gt;</strong></pre><p>then create this one for webserver to access html file :</p><pre><strong># setup-app.yml<br><br>---<br>  - hosts: webservers<br>    become: true<br>    tasks:<br>      - name: Upload application file<br>        copy:<br>          src: ../index.php<br>          dest: /var/www/html<br>          mode: 0755<br>      <br>      - name: Configure php.ini file<br>        lineinfile:<br>          path: /etc/php.ini<br>          regexp: ^short_open_tag<br>          line: &#39;short_open_tag=On&#39;<br>        notify: restart apache<br><br>    handlers:<br>      - name: restart apache<br>        service: name=httpd state=restarted</strong></pre><p>lastly you will need a setup-lb.yml for loadbalancer setup:</p><pre>first create a config folder:</pre><pre><strong>$ mkdir ansible/config<br></strong>and use the following to setup loadbalancer<br>create a file called lb-config.j2 &amp; copy</pre><pre><strong>ProxyRequests off<br>&lt;Proxy balancer://webcluster &gt;<br>  {% for hosts in groups[&#39;webservers&#39;] %}<br>    BalancerMember http://{{hostvars[hosts][&#39;ansible_host&#39;]}}<br>  {% endfor %}<br>    ProxySet lbmethod=byrequests<br>&lt;/Proxy&gt;<br><br># Optional<br>&lt;Location /balancer-manager&gt;<br>  SetHandler balancer-manager<br>&lt;/Location&gt;<br><br>ProxyPass /balancer-manager !<br>ProxyPass / balancer://webcluster/</strong></pre><pre>Finally we are going to create last playbook for uploading template file </pre><pre><strong># setup-lb.yml<br><br>--- <br>  - hosts: loadbalancers<br>    become: true <br>    tasks:<br>      - name: Creating template<br>        template:<br>          src: ../config/lb-config.j2<br>          dest: /etc/httpd/conf.d/lb.conf<br>          owner: bin<br>          group: wheel<br>          mode: 064<br>        notify: restart apache<br><br>    handlers:<br>      - name: restart apache<br>        service: name=httpd state=restarted</strong></pre><p><strong>Testing and Running Playbook</strong></p><p>lets congregate all the playbooks we have created in all-playbooks.yml file in playbooks folder so we can run all at once.</p><pre><strong># all-playbooks.yml<br>---<br>  - import_playbook: yum-update.yml<br>  - import_playbook: install-services.yml<br>  - import_playbook: setup-app.yml<br>  - import_playbook: setup-lb.yml</strong></pre><pre>sameed@local:~/ansible$ ansible-playbooks/all-playbooks.yml</pre><p>Once this is done run the following command to orchestrate the playbooks at once &amp; see the magic!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*AoP8Eg5TFhw7lQVvG83pPg.png" /></figure><p>Now open the ip address of one of EC2 Instances or LoadBalancer to check the webpage is working or not.</p><p><strong>Summary:</strong></p><ul><li>Playbooks are an ordered lists of plays that can run tasks for configuration and orchestration.</li><li>These plays allows us to run commands on a group or subset of servers within our inventory.</li><li>Create infrastructure as a code that can be managed in a source control.</li><li>Playbooks can be run multiple times without affecting previous runs.</li></ul><p><strong>Reference links:</strong></p><p><a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html">Intro to playbooks - Ansible Documentation</a></p><p><a href="https://docs.ansible.com/ansible/latest/modules/modules_by_category.html">https://docs.ansible.com/ansible/latest/modules/modules_by_category.html</a></p><p><a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html">https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html</a></p><p><a href="https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html">https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html</a></p><p>Thank you for reading!</p><p>Please Do give a Clap, Share your thoughts and suggestions…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dba17c9fa64" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>