Terraform installation via wget
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base/basevaribale$ wget https://releases.hashicorp.com/terraform/0.8.0/terraform_0.8.0_linux_amd64.zip
Then unzip the directory and update in bash profile.
you can strat with terraform version command to check version
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base/basevaribale$ terraform version
Terraform v0.12.21
Installing via configuration management
There are also configuration management resources available for installing Terraform.
You can find:
• A Puppet module for Terraform.
• A Chef cookbook for Terraform.
• An Ansible role for Terraform.
• A Terraform Docker container.
Getting started
Terraform (init/apply/plan/validate)
https://www.terraform.io/docs/providers/aws/r/instance.html
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ ################INITILIZATION OF AWS IN TERRAFORM###################
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ cat base.tf
provider "aws" {
region = "ap-south-1"
access_key = "AKIAJCQWLV3LYUWPIQVQ"
secret_key = "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"
}
resource "aws_instance" "lava" {
ami = "ami-0d9462a653c34dab7"
instance_type = "t2.micro"
key_name = "TEST"
}
resource "aws_eip" "lavaeip" {
instance = "aws_instance.lava.id"
vpc = true
}
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ terraform init
Initializing the backend...
Initializing provider plugins...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.aws: version = "~> 2.50"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ terraform validate
Success! The configuration is valid.
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ terraform 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.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_eip.lavaeip will be created
+ resource "aws_eip" "lavaeip" {
+ allocation_id = (known after apply)
+ association_id = (known after apply)
+ domain = (known after apply)
+ id = (known after apply)
+ instance = "aws_instance.lava.id"
+ network_interface = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ public_ipv4_pool = (known after apply)
+ vpc = true
}
# aws_instance.lava will be created
+ resource "aws_instance" "lava" {
+ ami = "ami-0d9462a653c34dab7"
+ arn = (known after apply)
+ associate_public_ip_address = (known after apply)
+ availability_zone = (known after apply)
+ cpu_core_count = (known after apply)
+ cpu_threads_per_core = (known after apply)
+ get_password_data = false
+ host_id = (known after apply)
+ id = (known after apply)
+ instance_state = (known after apply)
+ instance_type = "t2.micro"
+ ipv6_address_count = (known after apply)
+ ipv6_addresses = (known after apply)
+ key_name = "TEST"
+ network_interface_id = (known after apply)
+ password_data = (known after apply)
+ placement_group = (known after apply)
+ primary_network_interface_id = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ security_groups = (known after apply)
+ source_dest_check = true
+ subnet_id = (known after apply)
+ tenancy = (known after apply)
+ volume_tags = (known after apply)
+ vpc_security_group_ids = (known after apply)
+ ebs_block_device {
+ delete_on_termination = (known after apply)
+ device_name = (known after apply)
+ encrypted = (known after apply)
+ iops = (known after apply)
+ kms_key_id = (known after apply)
+ snapshot_id = (known after apply)
+ volume_id = (known after apply)
+ volume_size = (known after apply)
+ volume_type = (known after apply)
}
+ ephemeral_block_device {
+ device_name = (known after apply)
+ no_device = (known after apply)
+ virtual_name = (known after apply)
}
+ network_interface {
+ delete_on_termination = (known after apply)
+ device_index = (known after apply)
+ network_interface_id = (known after apply)
}
+ root_block_device {
+ delete_on_termination = (known after apply)
+ encrypted = (known after apply)
+ iops = (known after apply)
+ kms_key_id = (known after apply)
+ volume_id = (known after apply)
+ volume_size = (known after apply)
+ volume_type = (known after apply)
}
}
Plan: 2 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$ terraform plan -out lava.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.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_eip.lavaeip will be created
+ resource "aws_eip" "lavaeip" {
+ allocation_id = (known after apply)
+ association_id = (known after apply)
+ domain = (known after apply)
+ id = (known after apply)
+ instance = "aws_instance.lava.id"
+ network_interface = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ public_ipv4_pool = (known after apply)
+ vpc = true
}
# aws_instance.lava will be created
+ resource "aws_instance" "lava" {
+ ami = "ami-0d9462a653c34dab7"
+ arn = (known after apply)
+ associate_public_ip_address = (known after apply)
+ availability_zone = (known after apply)
+ cpu_core_count = (known after apply)
+ cpu_threads_per_core = (known after apply)
+ get_password_data = false
+ host_id = (known after apply)
+ id = (known after apply)
+ instance_state = (known after apply)
+ instance_type = "t2.micro"
+ ipv6_address_count = (known after apply)
+ ipv6_addresses = (known after apply)
+ key_name = "TEST"
+ network_interface_id = (known after apply)
+ password_data = (known after apply)
+ placement_group = (known after apply)
+ primary_network_interface_id = (known after apply)
+ private_dns = (known after apply)
+ private_ip = (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
+ security_groups = (known after apply)
+ source_dest_check = true
+ subnet_id = (known after apply)
+ tenancy = (known after apply)
+ volume_tags = (known after apply)
+ vpc_security_group_ids = (known after apply)
+ ebs_block_device {
+ delete_on_termination = (known after apply)
+ device_name = (known after apply)
+ encrypted = (known after apply)
+ iops = (known after apply)
+ kms_key_id = (known after apply)
+ snapshot_id = (known after apply)
+ volume_id = (known after apply)
+ volume_size = (known after apply)
+ volume_type = (known after apply)
}
+ ephemeral_block_device {
+ device_name = (known after apply)
+ no_device = (known after apply)
+ virtual_name = (known after apply)
}
+ network_interface {
+ delete_on_termination = (known after apply)
+ device_index = (known after apply)
+ network_interface_id = (known after apply)
}
+ root_block_device {
+ delete_on_termination = (known after apply)
+ encrypted = (known after apply)
+ iops = (known after apply)
+ kms_key_id = (known after apply)
+ volume_id = (known after apply)
+ volume_size = (known after apply)
+ volume_type = (known after apply)
}
}
Plan: 2 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
This plan was saved to: lava.plan
To perform exactly these actions, run the following command to apply:
terraform apply "lava.plan"
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base$
ubuntu@kubernetes-worker:~/terraform-project/terrformcfg/base/basevaribale$ ls -ltr
total 20
-rw-rw-r-- 1 ubuntu ubuntu 2044 Feb 29 10:00 basevar.plan
-rw-rw-r-- 1 ubuntu ubuntu 2876 Feb 29 10:15 terraform.tfstate.backup
-rw-rw-r-- 1 ubuntu ubuntu 157 Feb 29 10:27 terraform.tfstate
-rw-rw-r-- 1 ubuntu ubuntu 540 Feb 29 10:30 var.tf
-rw-rw-r-- 1 ubuntu ubuntu 206 Feb 29 10:49 basevar.tf
Type constraint:
it is used restrict all unwanted values and allows the required value from variable which is declared in var.tf

