Terraform code for AWS Ec2 instance creation

Sample Terraform Code:

provider "aws" {
  region = "us-east-1"
access_key = "xxxxxxxxxxxxxxFQQ"
secret_key = "fmxxxxxxxxxxxxxxxxxxxxx1JuV"
}
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_instance" "web" {
  ami           = "${data.aws_ami.ubuntu.id}"
  instance_type = "t2.micro"
key_name = "newkeyaug2017"
  tags {
    Name = "HelloWorld"
  }
}





C:\Users\sjaganathan\Documents\terraform-aws>terraform.exe validate

C:\Users\sjaganathan\Documents\terraform-aws>terraform.exe plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.aws_ami.ubuntu: Refreshing state...
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

+ aws_instance.web
    ami:                         "ami-7dce6507"
    associate_public_ip_address: ""
    availability_zone:           ""
    ebs_block_device.#:          ""
    ephemeral_block_device.#:    ""
    instance_state:              ""
    instance_type:               "t2.micro"
    ipv6_addresses.#:            ""
    key_name:                    "newkeyaug2017"
    network_interface_id:        ""
    placement_group:             ""
    private_dns:                 ""
    private_ip:                  ""
    public_dns:                  ""
    public_ip:                   ""
    root_block_device.#:         ""
    security_groups.#:           ""
    source_dest_check:           "true"
    subnet_id:                   ""
    tags.%:                      "1"
    tags.Name:                   "HelloWorld"
    tenancy:                     ""
    vpc_security_group_ids.#:    ""


Plan: 1 to add, 0 to change, 0 to destroy.

C:\Users\sjaganathan\Documents\terraform-aws>terraform.exe apply
data.aws_ami.ubuntu: Refreshing state...
aws_instance.web: Creating...
  ami:                         "" => "ami-7dce6507"
  associate_public_ip_address: "" => ""
  availability_zone:           "" => ""
  ebs_block_device.#:          "" => ""
  ephemeral_block_device.#:    "" => ""
  instance_state:              "" => ""
  instance_type:               "" => "t2.micro"
  ipv6_addresses.#:            "" => ""
  key_name:                    "" => "newkeyaug2017"
  network_interface_id:        "" => ""
  placement_group:             "" => ""
  private_dns:                 "" => ""
  private_ip:                  "" => ""
  public_dns:                  "" => ""
  public_ip:                   "" => ""
  root_block_device.#:         "" => ""
  security_groups.#:           "" => ""
  source_dest_check:           "" => "true"
  subnet_id:                   "" => ""
  tags.%:                      "" => "1"
  tags.Name:                   "" => "HelloWorld"
  tenancy:                     "" => ""
  vpc_security_group_ids.#:    "" => ""
aws_instance.web: Still creating... (10s elapsed)
aws_instance.web: Creation complete (ID: i-00a8c11897b8f9532)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:

C:\Users\sjaganathan\Documents\terraform-aws>

No comments:

Installing Ingress Controller - Kubernetes

Installing the Ingress Controller Prerequisites Make sure you have access to the Ingress controller image: For NGINX Ingress controll...