Terminating or destroying a build

To remove/terminate or destroy a build, it pretty simple. You use the terraform destroy command

 ayan@Epoch:~/terraform$ terraform destroy aws_instance.example: Refreshing state... (ID: i-065b6f952bd9dc3e0) 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 all resources?   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-065b6f952bd9dc3e0) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 10s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 20s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 30s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 40s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 50s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 1m0s elapsed) aws_instance.example: Still destroying... (ID: i-065b6f952bd9dc3e0, 1m10s elapsed) aws_instance.example: Destruction complete after 1m19s Destroy complete! Resources: 1 destroyed.
Shutting down
Terminated

Destroying the infrastructure does not automatically remove the source files though

ayan@Epoch:~/terraform$ ls -lrth total 12K -rwxrwxrwx 1 ayan ayan  243 Jan  3 18:00 aws.tf -rw-rw-r-- 1 ayan ayan 3.9K Jan  4 15:17 terraform.tfstate.backup -rw-rw-r-- 1 ayan ayan  319 Jan  4 15:17 terraform.tfstate

But it does change the state file

{     "version": 3,     "terraform_version": "0.11.11",     "serial": 10,     "lineage": "0bda5f62-cdfc-ca79-284f-XXXX",     "modules": [         {             "path": [                 "root"             ],             "outputs": {},             "resources": {},             "depends_on": []         }     ] }

The backup file still has the previous data in case it is needed

{     "version": 3,     "terraform_version": "0.11.11",     "serial": 10,     "lineage": "0bda5f62-cdfc-ca79-284f-xx",     "modules": [         {             "path": [                 "root"             ],             "outputs": {},             "resources": {                 "aws_instance.example": {                     "type": "aws_instance",                     "depends_on": [],                     "primary": {                         "id": "i-xx",                         "attributes": {                             "ami": "ami-xx",                             "arn": "arn:aws:ec2:us-east-1:xx:instance/i-065b6f952bd9dc3e0",                             "associate_public_ip_address": "true",                             "availability_zone": "us-east-1c",                             "cpu_core_count": "1",                             "cpu_threads_per_core": "1",                             "credit_specification.#": "1",                             "credit_specification.0.cpu_credits": "standard",                             "disable_api_termination": "false",                             "ebs_block_device.#": "0",                             "ebs_optimized": "false",                             "ephemeral_block_device.#": "0",                             "get_password_data": "false",                             "iam_instance_profile": "",                             "id": "i-065b6f952bd9dc3e0",                             "instance_state": "running",                             "instance_type": "t2.micro",                             "ipv6_addresses.#": "0",                             "key_name": "",                             "monitoring": "false",                             "network_interface.#": "0",                             "network_interface_id": "eni-xx",                             "password_data": "",                             "placement_group": "",                             "primary_network_interface_id": "eni-xx",                             "private_dns": "ip-172-31-92-107.ec2.internal",                             "private_ip": "xx",                             "public_dns": "ecxx.compute-1.amazonaws.com",                             "public_ip": "xx",                             "root_block_device.#": "1",                             "root_block_device.0.delete_on_termination": "true",                             "root_block_device.0.iops": "100",                             "root_block_device.0.volume_id": "vol-xx",                             "root_block_device.0.volume_size": "8",                             "root_block_device.0.volume_type": "gp2",                             "security_groups.#": "1",                             "security_groups.xx": "default",                             "source_dest_check": "true",                             "subnet_id": "subnet-xx",                             "tags.%": "0",                             "tenancy": "default",                             "volume_tags.%": "0",                             "vpc_security_group_ids.#": "1",                             "vpc_security_group_ids.xx": "sg-xx"                         },                         "meta": {                             "xx-ecaa-11e6-8f88-xx": {                                 "create": 600000000000,                                 "delete": 1200000000000,                                 "update": 600000000000                             },                             "schema_version": "1"                         },                         "tainted": false                     },                     "deposed": [],                     "provider": "provider.aws"                 }             },             "depends_on": []         }     ] } terraform.tfstate.backup (END)

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous post Getting Started with Terraform
Next post VMware ESXi Logs