Após a aula 03 do curso Terraform:Automatize a infraestrutura na nuvem, eu apaguei e recriei tudo, pois na primeira tentativa de acompanhamento a Amazon reclamou que o bucket deveria ser criado na região sa-east-1 e não na us-east-1 como eu vinha fazendo desde o início das instruções.
Porém, após o init e plan bem-sucedidos, o apply retornou o seguinte:
Error: Error creating Security Group: InvalidGroup.Duplicate: The security group 'acesso-ssh' already exists for VPC 'vpc-ca58b1b7'
status code: 400, request id: 99f1e01f-2585-4ec5-8f23-74791991ebbf
Error: Error import KeyPair: InvalidKeyPair.Duplicate: The keypair 'terraform-aws' already exists.
status code: 400, request id: 332a1c76-4d9b-4fe8-b205-87b4711b31e6
Error: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
status code: 409, request id: 0EE0B5F0119B4F04, host id: 8d2mTwIe8DSGF7IZIQ1SVCp17YgvuAoHQVFkpaaohQweIzqTHOmJeYGidb9472DmquofhU3LNcI=
Segue o meu main.tf:
provider "aws"{
version = "~> 3.0"
region = "us-east-1"
}
resource "aws_key_pair" "terraform_aws" {
key_name = "terraform-aws"
public_key = file("C:\\Users\\admin\\.ssh\\terraform-aws.pub")
}
resource "aws_instance" "dev" {
count = 3
ami = "ami-026c8acd92718196b"
instance_type = "t2.micro"
key_name = aws_key_pair.terraform_aws.key_name
tags = {
Name = "dev${count.index}"
}
vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
}
resource "aws_instance" "dev4" {
ami = "ami-026c8acd92718196b"
instance_type = "t2.micro"
key_name = "terraform-aws"
tags = {
Name = "dev4"
}
vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
depends_on = [aws_s3_bucket.dev4]
}
resource "aws_instance" "dev5" {
ami = "ami-026c8acd92718196b"
instance_type = "t2.micro"
key_name = "terraform-aws"
tags = {
Name = "dev5"
}
vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
}
resource "aws_security_group" "acesso-ssh" {
name = "acesso-ssh"
description = "acesso-ssh"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
# Please restrict your ingress to only necessary IPs and ports.
# Opening to 0.0.0.0/0 can lead to security vulnerabilities.
cidr_blocks = ["191.176.132.35/32"]
}
tags = {
Name = "ssh"
}
}
resource "aws_s3_bucket" "dev4" {
bucket = "linolabs-dev4"
acl = "private"
tags = {
Name = "linolabs-dev4"
}
}
Qual seria, então, a melhor forma de limpar e recriar tudo sem incorrer nesse problema?
Abraços.