Wednesday, December 22, 2021

AWS Automation using Terraform

What is Terraform?



HashiCorp Terraform is an open-source infrastructure as code (IaC) software tool that allows DevOps engineers to programmatically provision the physical resources an application requires to run. Infrastructure as code is an IT practice that manages an application's underlying IT infrastructure through programming.

What is AWS Automation?

Automation, a capability of AWS Systems Manager, simplifies common maintenance and deployment tasks of Amazon Elastic Compute Cloud (Amazon EC2) instances and other AWS resources. ... Build automations to configure and manage instances and AWS resources.



Here is a full tutorial video (Concept + Demo) based on "How we can do AWS Automation using Terraform"👇👇



Resource: aws_launch_configuration

Provides a resource to create a new launch configuration, used for autoscaling groups.

Example Usage

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_launch_configuration" "as_conf" {
  name          = "web_config"
  image_id      = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"
}

Using with AutoScaling Groups

Launch Configurations cannot be updated after creation with the Amazon Web Service API. In order to update a Launch Configuration, Terraform will destroy the existing resource and create a replacement. In order to effectively use a Launch Configuration resource with an AutoScaling Group resource, it's recommended to specify create_before_destroy in a lifecycle block. Either omit the Launch Configuration name attribute, or specify a partial name with name_prefix. Example:

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_launch_configuration" "as_conf" {
  name_prefix   = "terraform-lc-example-"
  image_id      = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "bar" {
  name                 = "terraform-asg-example"
  launch_configuration = aws_launch_configuration.as_conf.name
  min_size             = 1
  max_size             = 2

  lifecycle {
    create_before_destroy = true
  }
}

With this setup Terraform generates a unique name for your Launch Configuration and can then update the AutoScaling Group without conflict before destroying the previous Launch Configuration.




I HOPE YOU ALL ARE CLEAR WITH THIS, 

IF YOU ARE FACING ANY PROBLEM THEN YOU CAN TAKE HELP OF ABOVE VIDEO.






▬▬▬▬▬▬ WANT TO LEARN MORE? ▬▬▬▬▬▬


Full Terraform tutorial ►
https://bit.ly/2GwK8V2 DevOps Tools, like Ansible ► https://bit.ly/3iASHuP Docker Tutorial ► https://bit.ly/3iAT9Jx AWS Tutorial ► https://bit.ly/30GFv1q GCP Tutorial ► https://bit.ly/3mwh412 Jenkins Tutorials ► https://bit.ly/3iHnfv4 Jenkins Pipeline ► https://bit.ly/30CJGLB Python ► https://bit.ly/3I7bewU Python in just 1 video ► https://bit.ly/3EeqGVy


1 comment:


  1. It's pretty astonishing how effortlessly you define and explain things!
    visit us 

    ReplyDelete

Wireless Security Configuration: Protect Your Network Now!

Introduction: In today’s connected world, wireless networks are as common as smartphones, and they’re often the gateway to our personal, pr...