Auto-rollback the changes if terraform job failed between execution step
Working with one .tf file which include creation of s3 bucket,ec2 and security group, my concern is that if i ran terraform apply and it successfully created s3 bucket after that abort in between . In above case i wanted to rollback the all changes happened after terraform apply ran.
Once .tf file started running ,i had abort the process but changes won't rollback.
provider "aws" { }
resource "aws_instance" "example" {
ami = "ami-2757f631"
instance_type = "t2.micro"
}
resource "aws_s3_bucket" "b" {
bucket = "my-tf-test-bucket"
acl = "private"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
resource "aws_security_group" "allow_rdp" {
name = "allow_rdp"
description = "Allow rdp traffic"
ingress {
from_port = 3389 # By default, the windows server listens on TCP port 3389 for RDP
to_port = 3389
protocol = "tcp"
}
}