<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SanjaiKumar2311</title>
    <description>The latest articles on DEV Community by SanjaiKumar2311 (@sanjaikumar2311).</description>
    <link>https://dev.to/sanjaikumar2311</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1437855%2F42b9a1d3-5354-4e11-b2d2-53948f1fa0bc.jpg</url>
      <title>DEV Community: SanjaiKumar2311</title>
      <link>https://dev.to/sanjaikumar2311</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanjaikumar2311"/>
    <language>en</language>
    <item>
      <title>CREATE SPOTIFY PLAYLIST USING TERRAFORM</title>
      <dc:creator>SanjaiKumar2311</dc:creator>
      <pubDate>Tue, 13 Aug 2024 13:35:45 +0000</pubDate>
      <link>https://dev.to/sanjaikumar2311/creat-spotify-playlist-using-terraform-aao</link>
      <guid>https://dev.to/sanjaikumar2311/creat-spotify-playlist-using-terraform-aao</guid>
      <description>&lt;p&gt;In this blog, I'll walk you through creating Spotify playlists using Terraform. This process involves setting up the necessary files, configuring the Spotify provider, and running the Terraform commands to automate playlist creation. Below are the prerequisites and the step-by-step guide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Prerequisites:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Spotify Account: **You need an active Spotify account to generate the API keys.&lt;br&gt;
**Docker Installed:&lt;/strong&gt; Ensure Docker is installed on your machine to run Terraform in a container.&lt;br&gt;
**Terraform Installed: **Have Terraform installed and configured on your local machine.&lt;br&gt;
**Spotify Developer Account: **Create an account on Spotify Developer Dashboard and generate your client ID and secret key.&lt;/p&gt;

&lt;p&gt;Step 1: Setting Up Your Terraform Files&lt;br&gt;
We'll start by creating the necessary Terraform files. Here's what each file does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;terraform.tf
This file is the main configuration for Terraform. It specifies the provider and the version we're going to use.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    spotify = {
      source = "conradludgate/spotify"
      version = "0.2.7"
    }
  }
}

provider "spotify" {
  api_key = var.api_key
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;variable.tf
This file is where we define our variables. In this case, we need to store our Spotify API key.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable "api_key" {
  type = string
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;playlist.tf
This file contains the resources that Terraform will create. We're setting up two playlists here: one for Kollywood music and another for Eminem's tracks.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "spotify_playlist" "kollywood" {
  name  = "Kollywood"
  tracks = ["1hHrBEkN0JIaeFPegy4Xak"]
}

data "spotify_search_track" "eninem" {
  artist = "Eminem"
  limit  = 3
}

resource "spotify_playlist" "slimShady" {
  name  = "Slim Shady"
  tracks = [
    data.spotify_search_track.eninem.tracks[0].id,
    data.spotify_search_track.eninem.tracks[1].id,
    data.spotify_search_track.eninem.tracks[2].id
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;terraform.tfvars
This file is where we provide the value for the API key. Replace "nUsXPGiNSd3wVHmCz_UH--D347MnBYbuGG4j3xB3wwerPGKtcoyYrBLXz36ovDA2" with your actual API key.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;api_key = "nUsXPGiNSd3wVHmCz_UH--D347MnBYbuGG4j3xB3wwerPGKtcoyYrBLXz36ovDA2"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;.env
This file stores your Spotify Client ID and Secret. Make sure you don't share this file publicly.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_secret_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Setting Up Your Spotify Developer Account&lt;/p&gt;

&lt;p&gt;Go to the Spotify Developer Dashboard.&lt;br&gt;
Click on "Create an App" and fill out the required details.&lt;br&gt;
Once the app is created, you'll be given a Client ID and a Client Secret. Store these in the .env file as shown above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;br&gt;
 Running Terraform&lt;br&gt;
Open your terminal and navigate to the directory containing your Terraform files.&lt;br&gt;
Run the following commands to initialize and apply your Terraform configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terraform will prompt you to confirm the changes. Type yes and hit enter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Verifying the Playlists&lt;br&gt;
Once Terraform has finished running, head over to your Spotify account and check your playlists. You should see two new playlists: Kollywood and Slim Shady. The Kollywood playlist will have a single track, while the Slim Shady playlist will have three Eminem tracks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89v2qapdsv5szgzourde.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89v2qapdsv5szgzourde.png" alt="Image description" width="800" height="358"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7prv7j7dz87hpo9o6zuu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7prv7j7dz87hpo9o6zuu.png" alt="Image description" width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>spotify</category>
    </item>
    <item>
      <title>Hosting Static Website On S3 Using Terraform</title>
      <dc:creator>SanjaiKumar2311</dc:creator>
      <pubDate>Thu, 27 Jun 2024 21:49:09 +0000</pubDate>
      <link>https://dev.to/sanjaikumar2311/hosting-static-website-on-s3-using-terraform-5bp6</link>
      <guid>https://dev.to/sanjaikumar2311/hosting-static-website-on-s3-using-terraform-5bp6</guid>
      <description>&lt;p&gt;In this blog we'll dive into deploying a static website on AWS S3 using Terrafrom!&lt;br&gt;
Important things to note:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Automating S3 Bucket Creation: Terraform will handle creating the S3 bucket where your website files will reside.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.Effortless Website Upload: We’ll configure Terraform to skip manual uploads by referencing your website files locally.&lt;/p&gt;

&lt;p&gt;3.Public Access for All: Terraform will configure the S3 bucket policy to grant public read access, ensuring anyone can access your website.&lt;/p&gt;

&lt;p&gt;How it is working by using Terraform?&lt;br&gt;
Terraform is an infrastructure as code (IaC) tool used to define and manage cloud resources means we don't need to specify anything using console just we specify what are the resources we are going to use. Terraform will offers pre-built configurations for the various services.Terraform script that automates the entire deployment process, saving you time and ensuring a secure and accessible website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setup the Terraform&lt;br&gt;
Create a terraform.tf file to set up the terraform and provider.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_version = "1.7.4"
  required_providers {
    aws = {
        source = "hashicorp/aws"
        version = "5.40.0"
    }
  }
}

#Provider
provider "aws" {
  profile = "default"
  region = "ap-south-1"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code version is "1.7.4",you can mention your Terraform version.&lt;br&gt;
Terraform block defines its configuration and required_providers section defines external provider.&lt;br&gt;
A crucial element within provider "aws" block is the&lt;br&gt;
[profile = "default"]setting. This tells Terraform to use the default profile configured in your AWS credentials.Region section tells us which region we are going to create the S3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configuration for S3 bucket&lt;br&gt;
Create a bucket.tf file to store the terraform configuration related to the S3 bucket.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create S3 Bucket
resource "aws_s3_bucket" "terraform-demo-43234" {
  bucket = "terraform-demo-43234"
}

# Upload file to S3
resource "aws_s3_object" "terraform_index" {
  bucket = aws_s3_bucket.terraform-demo-43234.id
  key = "index.html"
  source = "index.html"
  content_type = "text/html"
  etag = filemd5("index.html")
}

# S3 Web hosting
resource "aws_s3_bucket_website_configuration" "terraform_hosting" {
  bucket = aws_s3_bucket.terraform-demo-43234.id

  index_document {
    suffix = "index.html"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resource “aws_s3_bucket” “terraform-demo-43234” block creates a new S3 bucket named “terraform-demo-43234”. (Error:if you got a error like bucket already exist please mention any other unique name for the bucket)&lt;br&gt;
Resource “aws_s3_object” “terraform_index” block upload a &lt;br&gt;
*&lt;em&gt;index.html *&lt;/em&gt; to the S3 bucket.It defines the bucket in the form "aws_s3_bucket.bucket_name.id".Source property tells Terraform where to find the "index.html" file on your local machine.&lt;br&gt;
content_type tells the content format.The etag property plays a crucial role in ensuring data integrity during file uploads, particularly in Terraform with S3 buckets.&lt;br&gt;
Resource “aws_s3_bucket_website_configuration” “terraform_hosting”) block configures the S3 bucket for website hosting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configuration for bucket Policy&lt;br&gt;
Create a ‘policy.tf’ file to store the terraform configuration related to the bucket policy for public access.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# S3 public access
resource "aws_s3_bucket_public_access_block" "terraform-demo" {
    bucket = aws_s3_bucket.terraform-demo-43234.id
  block_public_acls = false
  block_public_policy = false
}

# S3 public Read policy
resource "aws_s3_bucket_policy" "open_access" {
  bucket = aws_s3_bucket.terraform-demo-43234.id

  policy = jsonencode({
    Version = "2012-10-17"
    Id      = "Public_access"
    Statement = [
      {
        Sid = "IPAllow"
        Effect = "Allow"
        Principal = "*"
        Action = ["s3:GetObject"]
        Resource = "${aws_s3_bucket.terraform-demo-43234.arn}/*"
      },
    ]
  })
  depends_on = [ aws_s3_bucket_public_access_block.terraform-demo ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This block temporarily disables S3’s default Block Public Access settings for this specific bucket. &lt;br&gt;
bucket = aws_s3_bucket.terraform-demo-43234.id: References the S3 bucket we created earlier.block_public_acls = false: Disables blocking of public access control lists (ACLs).block_public_policy = false: Disables blocking of public bucket policies.&lt;br&gt;
policy = jsonencode({ ... }): Specifies the actual policy document in JSON format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Configuration for Output variable&lt;br&gt;
Create an ‘output.tf’ to print out the URL to access the website.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Website URL
output "website_url" {
  value = "http://${aws_s3_bucket.terraform-demo-43234.bucket}.s3-website.${aws_s3_bucket.terraform-demo-43234.region}.amazonaws.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you completed all this process.Open the command prompt or terminal &amp;amp; navigate to the folder where the terraform file is located.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Initialize Terraform&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It downloads and installs any required provider plugins based on your configuration like hashicorp/aws provider.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Terraform Validate&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform validate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It performs a static analysis of your Terraform configuration files and validates the overall syntax of your Terraform code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Terraform Plan&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is used for reviewing the intended changes to your infrastructure before actually applying them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Terraform Apply&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform apply

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Terraform apply command in Terraform is the one that actually executes the actions outlined in the plan generated by the Terraform plan. &lt;/p&gt;

&lt;p&gt;If it runs successfully then open the AWS console to verify the S3 bucket is created and to check the file is upload in the S3 bucket.&lt;br&gt;
At last the output(url) will display in cmd prompt.Copy and paste the url in the google to see the uploaded file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9: Destroy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terraform destroy command in Terraform is used for deleting the s3 bucket and its objects. &lt;/p&gt;

</description>
      <category>terraform</category>
      <category>s3</category>
      <category>website</category>
    </item>
    <item>
      <title>Terraform Basics</title>
      <dc:creator>SanjaiKumar2311</dc:creator>
      <pubDate>Wed, 26 Jun 2024 01:48:11 +0000</pubDate>
      <link>https://dev.to/sanjaikumar2311/terraform-basics-1d2j</link>
      <guid>https://dev.to/sanjaikumar2311/terraform-basics-1d2j</guid>
      <description>&lt;p&gt;Infrastructure as Code (IaC) tools allow you to manage infrastructure with configuration files rather than through a graphical user interface.Terraform is HashiCorp's infrastructure as code tool.HashiCorp's is the company that develop the terraform.It describes the desired end-state for your infrastructure, in contrast to procedural programming languages that require step-by-step instructions to perform tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FEATURES&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;multiple cloud platforms.
2.The human-readable configuration language.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To deploy infrastructure with Terraform:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;- Scope - identifying infrastructure&lt;/li&gt;
&lt;li&gt;- Author - to write the configuration&lt;/li&gt;
&lt;li&gt;- Initialize - install the packages&lt;/li&gt;
&lt;li&gt;- Plan - preview the changes&lt;/li&gt;
&lt;li&gt;- Apply -after all this process it is ready to implement.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This blog gives you a complete step-by-step guide that explains you how to create, modify and delete a VM using Terraform CLI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INSTALLATION&lt;/strong&gt;&lt;br&gt;
   1.Before going to install Terraform, we are going install chocolatey using command in powershell administrator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;After that we are going to install Terraform app and then install the Terraform extension using the command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;choco install Terraform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Then we can check if Terraform is installed correctly by using the command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform -help
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;BUILD INFRASTRUCTURE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;br&gt;
To follow this tutorial you will need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Terraform CLI (1.2.0+) installed.&lt;/li&gt;
&lt;li&gt;The AWS CLI installed.&lt;/li&gt;
&lt;li&gt;AWS account and associated credentials that allow you to create resources.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now go to command prompt and then connect cli with aws console by creating acccess key and secret key.&lt;/p&gt;

&lt;p&gt;After that create the directory using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir learn-terraform-aws-instance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change into the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd learn-terraform-aws-instance

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file to define your infrastructure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code main.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the code in main.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~&amp;gt; 4.16"
    }
  }

  required_version = "&amp;gt;= 1.2.0"
}

provider "aws" {
  region  = "us-west-2"
}

resource "aws_instance" "app_server" {
  ami           = "ami-830c94e3"
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleAppServerInstance"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;paste the code in any coding platform and go to cmd.&lt;/p&gt;

&lt;p&gt;Initialize the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After finishing this go to console their you see one EC2 instance is running. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHANGE INFRASTRUCTURE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initialize the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now update the ami of your instance. Change the aws_instance.app_server resource under the provider block in main.tf by replacing the current AMI ID with a new one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; resource "aws_instance" "app_server" {
   ami           = "ami-08d70e59c07c61a3a"
   instance_type = "t2.micro"
 }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DESTROY&lt;/strong&gt;&lt;br&gt;
The terraform destroy command terminates resources managed by your Terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Answer yes to execute this plan and destroy the infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define input variables&lt;/strong&gt;&lt;br&gt;
Change into the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd learn-terraform-aws-instance

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file to define your infrastructure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code main.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the code in main.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~&amp;gt; 4.16"
    }
  }

  required_version = "&amp;gt;= 1.2.0"
}

provider "aws" {
  region  = "us-west-2"
}

resource "aws_instance" "app_server" {
  ami           = "ami-08d70e59c07c61a3a"
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleAppServerInstance"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a new file called variables.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable "instance_name" {
  description = "Value of the Name tag for the EC2 instance"
  type        = string
  default     = "ExampleAppServerInstance"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In main.tf, update the aws_instance resource block to use the new variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; resource "aws_instance" "app_server" {
   ami           = "ami-08d70e59c07c61a3a"
   instance_type = "t2.micro"

   tags = {
-    Name = "ExampleAppServerInstance"
+    Name = var.instance_name
   }
 }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if we apply the above instruction it doesn't change anything once you apply the command and Respond to the confirmation prompt with yes.The instance name will change automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply -var "instance_name=YetAnotherName"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Define input variables&lt;/strong&gt;&lt;br&gt;
Follow the same step as wee follow in input variable definition. In this we add one more file called output.tf.&lt;br&gt;
Add the configuration below to outputs.tf to define outputs for your EC2 instance's ID and IP address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output "instance_id" {
  description = "ID of the EC2 instance"
  value       = aws_instance.app_server.id
}

output "instance_public_ip" {
  description = "Public IP address of the EC2 instance"
  value       = aws_instance.app_server.public_ip
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output will be displayed on the cmd and we need to delete the EC2 instance .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Answer yes to execute this plan and destroy the infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Store remote state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Change into the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd learn-terraform-aws-instance

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file to define your infrastructure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code main.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the code in main.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~&amp;gt; 4.16"
    }
  }

  required_version = "&amp;gt;= 1.2.0"
}

provider "aws" {
  region  = "us-west-2"
}

resource "aws_instance" "app_server" {
  ami           = "ami-08d70e59c07c61a3a"
  instance_type = "t2.micro"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the configuration. Respond to the confirmation prompt with a yes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set up HCP Terraform&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have a HashiCorp Cloud Platform or HCP Terraform account, log in using your existing credentials and create an organization.&lt;/p&gt;

&lt;p&gt;Modify main.tf to add a cloud block to your Terraform configuration, and replace organization-name with your organization name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  cloud {
    organization = "organization-name"
    workspaces {
      name = "learn-terraform-aws"
    }
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Login to HCP Terraform&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform login

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm with a yes and follow the workflow in the browser window that will automatically open.And now it is asking for token,create a token and copy &amp;amp; paste it.&lt;br&gt;
It will login in to terraform.&lt;/p&gt;

&lt;p&gt;Initialize the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that Terraform has migrated the state file to HCP Terraform, delete the local state file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ del terraform.tfstate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terraform init step created the learn-terraform-aws workspace in your HCP Terraform organization.&lt;br&gt;
Navigate to your learn-terraform-aws workspace in HCP Terraform and go to the workspace's Variables page. Under Workspace Variables, add your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as Environment Variables, making sure to mark them as "Sensitive".&lt;/p&gt;

&lt;p&gt;Apply the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terraform will show that there are no changes to be made.Delete the instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Answer yes to execute this plan and destroy the infrastructure.&lt;/p&gt;

</description>
      <category>terraform</category>
    </item>
  </channel>
</rss>
