======================================= Terraform Practice Example ======================================= https://console.aws.amazon.com/iam/home?#/home https://console.aws.amazon.com/iam/home?#/users/adarshkumar?section=security_credentials Steps to run Terraform ============================= Step1: Download Terraform from Hasicorp Step2: Unzip in some directory - Normally it has just one file Step 3: Put the above in your system path windows or Linux Step4: Test by simply running terraform Step5: Goto AWS Console and get your "access Key" and "Secret _key" for the user who can loging and do the work in AWS Step6: Now Create a project directory Step7: Create any file say ec2.tf <== Note it has tf extension ( See example below) -- Start provider "aws" { access_key = "AKIAZY2JM46YFE36ABIC" secret_key = "7lpSIBNwEGN6I2ta1Ux/ESzZFf+YxZ1eCz2PA1yW" region = "us-east-1" } resource "aws_instance" "AKexample1" { ami = "ami-2757f631" instance_type = "t2.micro" } -- End Step8: While inside the project subdirectory initialize terraform init <== this will create more resource Step9: Now create resource by running terraform apply Step10: you can destroy the resource using terraform destroy ################### Sample Outputs ################### C:\terraform\Practice\Create_EC2>terraform init Initializing provider plugins... - Checking for available provider plugins on https://releases.hashicorp.com... - Downloading plugin for provider "aws" (2.29.0)... 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.29" Terraform has been successfully initialized! #### Apply ( output sample ) C:\terraform>terraform apply aws_instance.AKexample: Refreshing state... (ID: i-0070e20a2f9c4a6db) An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create - destroy Terraform will perform the following actions: - aws_instance.AKexample + aws_instance.AKexample2 id: ami: "ami-2757f631" associate_public_ip_address: availability_zone: ebs_block_device.#: ephemeral_block_device.#: get_password_data: "false" instance_state: instance_type: "t2.micro" ipv6_address_count: ipv6_addresses.#: key_name: network_interface.#: network_interface_id: password_data: placement_group: primary_network_interface_id: private_dns: private_ip: public_dns: public_ip: root_block_device.#: security_groups.#: source_dest_check: "true" subnet_id: tenancy: volume_tags.%: vpc_security_group_ids.#: Plan: 1 to add, 0 to change, 1 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes aws_instance.AKexample: Destroying... (ID: i-0070e20a2f9c4a6db) aws_instance.AKexample2: Creating... ami: "" => "ami-2757f631" associate_public_ip_address: "" => "" availability_zone: "" => "" ebs_block_device.#: "" => "" ephemeral_block_device.#: "" => "" get_password_data: "" => "false" instance_state: "" => "" instance_type: "" => "t2.micro" ipv6_address_count: "" => "" ipv6_addresses.#: "" => "" key_name: "" => "" network_interface.#: "" => "" network_interface_id: "" => "" password_data: "" => "" placement_group: "" => "" primary_network_interface_id: "" => "" private_dns: "" => "" private_ip: "" => "" public_dns: "" => "" public_ip: "" => "" root_block_device.#: "" => "" security_groups.#: "" => "" source_dest_check: "" => "true" subnet_id: "" => "" tenancy: "" => "" volume_tags.%: "" => "" vpc_security_group_ids.#: "" => "" aws_instance.AKexample: Still destroying... (ID: i-0070e20a2f9c4a6db, 10s elapsed) aws_instance.AKexample2: Still creating... (10s elapsed) aws_instance.AKexample: Still destroying... (ID: i-0070e20a2f9c4a6db, 20s elapsed) aws_instance.AKexample2: Still creating... (20s elapsed) aws_instance.AKexample2: Creation complete after 23s (ID: i-0acfb329cd2c2e6cf) aws_instance.AKexample: Still destroying... (ID: i-0070e20a2f9c4a6db, 30s elapsed) aws_instance.AKexample: Still destroying... (ID: i-0070e20a2f9c4a6db, 40s elapsed) aws_instance.AKexample: Still destroying... (ID: i-0070e20a2f9c4a6db, 50s elapsed) aws_instance.AKexample: Destruction complete after 51s Apply complete! Resources: 1 added, 0 changed, 1 destroyed.