===== Simple example =====
andrew@puppet:~/terraform/ec2-Build$ cat ec2-builder1.tf
# test build for simple ec2-instance
# Andrew 20/09/2018
provider "aws" {
assume_role {
role_arn = "arn:aws:iam::1234567890:role/sandbox"
}
access_key = "YourKeyHere"
secret_key = "YourSecretHere"
region = "eu-west-1" (Ireland)
}
resource "aws_instance" "example" {
ami = "ami-0bdb1d6c15a403123"
instance_type = "t2.micro"
}
andrew@puppet:~/terraform/ec2-Build$
This is built and destroyed thus:-
andrew@puppet:~/terraform/ec2-Build$ terraform init
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "aws" (1.37.0)...
andrew@puppet:~/terraform/ec2-Build$ 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_instance.example
id:
ami: "ami-0bdb123456789"
arn:
...edited...
ephemeral_block_device.#:
get_password_data: "false"
instance_state:
instance_type: "t2.micro"
...edited...
volume_tags.%:
vpc_security_group_ids.#:
Plan: 1 to add, 0 to change, 0 to destroy.
andrew@puppet:~/terraform/ec2-Build$ terraform apply
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_instance.example
id:
...edited...
vpc_security_group_ids.#:
Plan: 1 to add, 0 to change, 0 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.example: Creating...
ami: "" => "ami-0bdb123456789"
arn: "" => ""
associate_public_ip_address: "" => ""
...edited...
aws_instance.example: Creation complete after 32s (ID: i-07e6c7dec9c95f167)
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
andrew@puppet:~/terraform/ec2-Build$
andrew@puppet:~/terraform/ec2-Build$ terraform destroy
aws_instance.example: Refreshing state... (ID: i-07e6c7dec9c95f167)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
- aws_instance.example
Plan: 0 to add, 0 to change, 1 to destroy.
Do you really want to destroy?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
aws_instance.example: Destroying... (ID: i-)
aws_instance.example: Still destroying... (ID: i-07e6c7dec9c95f167, 10s elapsed)
...edited...
aws_instance.example: Still destroying... (ID: i-07e6c7dec9c95f167, 1m0s elapsed)
aws_instance.example: Destruction complete after 1m1s
Destroy complete! Resources: 1 destroyed.
andrew@puppet:~/terraform/ec2-Build$