*** Security-group.tf ***
resource "aws_security_group" "acesso-ssh" {
#provider = aws.us-east-1 name = "acesso-ssh" description = "Permite o acesso remoto via SSH"
vpc_id = aws_vpc.main.id
ingress { description = "SSH from VPC" from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["191.35.25.0/24"] }
egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] }
tags = { Name = "ssh" } }
resource "aws_security_group" "acesso-ssh-us-east-2" { provider = aws.us-east-2 name = "acesso-ssh" description = "Permite o acesso remoto via SSH"
vpc_id = aws_vpc.main.id
ingress { description = "SSH from VPC" from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["191.35.25.0/24"] }
egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] }
tags = { Name = "ssh" } }
*** main.tf *** terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } }
Configure the AWS Provider
provider "aws" {
#alias = "us-east-1" region = "us-east-1"
access_key = "access_key "
secret_key = "secret_key"
shared_credentials_file = "/Users/tf_user/.aws/creds"
profile = "customprofile"
}
provider "aws" { alias = "us-east-2" region = "us-east-2" }
Provisionamento das máquinas virtuais
resource "aws_instance" "dev" { count = 3 ami = "ami-042e8287309f5df03" instance_type = "t2.micro" key_name = "id_bionic" tags = { "Name" = "dev${count.index}" }
#vpc_security_group_ids = ["sg-0fb4d62974896a925"] vpc_security_group_ids = [aws_security_group.acesso-ssh.id] }
resource "aws_instance" "dev4" { ami = "ami-042e8287309f5df03" instance_type = "t2.micro" key_name = "id_bionic" 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-042e8287309f5df03" instance_type = "t2.micro" key_name = "id_bionic" tags = { "Name" = "dev5" } vpc_security_group_ids = [aws_security_group.acesso-ssh.id] }
/* resource "aws_instance" "dev6" { provider = aws.us-east-2 ami = "ami-089c6f2e3866f0f14" instance_type = "t2.micro" key_name = "id_bionic" tags = { "Name" = "dev6" } vpc_security_group_ids = [aws_security_group.acesso-ssh-us-east-2.id] } */
resource "aws_s3_bucket" "dev4" { bucket = "s3-bucket-dev4" acl = "private"
tags = { Name = "s3-bucket-dev4"
#Environment = "Dev"
} }
Segue abaixo o erro após executar o terraform plan.; terraform plan
Error: fork/exec .terraform/providers/registry.terraform.io/hashicorp/aws/3.34.0/linux_amd64/terraform-provider-aws_v3.34.0_x5: permission denied
Se eu comentar a linha 28, provider = aws.us-east-2, do resource "aws_security_group" "acesso-ssh-us-east-2" funciona perfeitamente.
Estou tentando caçar a solução na internet, mas até agora nada ...