aws configure --profile profile-name
aws configure list
terraform plan
``
### Terraform apply para aplicar as mudanças
terraform apply ``
Não é necessário informar o caminho shared_credentials_file, caso você tenha configurado um profile para credenciais na sua máquina
provider "aws" {
#shared_credentials_file="~/.aws/credentials"
profile="terraform-script"
region="us-east-1"
}
terraform show
terraform destroy
terraform taint [nome do recurso]
terraform untaint [nome do recurso]
terraform console
// [recurso.nome.variable]
variable "instance_type" {
}
variable "ami"{
default="ami-0b69ea66ff7391e80"
}
terraform plan -var 'instace_type=t2.micro'
terraform plan -var-file="dev.tfvars"
variable "tags" {
type="map"
default={
"Name"="NodeJs"
"Env"="Dev"
}
}
terraform fmt
terraform get
terrafomr import [resource] [resource_name]
terraform graph > base.dot
terraform{
backend "s3"{
bucket="${var.bucket_name}"
key="ec2/ec2.tfstate"
region="${var.region}"
}
}
terraform init -backend=true -backend-config="bucket_name=jax-remote-state-dev" -backend-config="region=us-east-1 -backend-config="profile=terraform"
Data source permite que dados sejam buscados e computados de algum lugar para ser usado pelo terraform
data "aws_ami" "ubuntu" {
owners = ["amazon"]
most_recent = true
name_regex = "ubuntu"
}
resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.instance_type}"
}
terraform init -backend=true \
> -backend-config="region=us-east-1" \
> -backend-config="bucket=jax-remote-state-dev" \
> -backend-config="key=ec2/wc2.tfstate" \
> -backend-config="profile=terraform"
TF_LOG=debug terraform [command]
terraform output ami
locals {
instan_id = "${data.terraform_remote_state.web.id}"
ami = "${data.terraform_remote_state.web.ami}"
arn = "${data.terraform_remote_state.web.arn}"
}
Chamando
module "bucket"{
source="../../04-Modules/S3"
name="${var.bucket_name}-${var.env}"
versioning=true
tag ={
"Env"="${var.env}"
"Name" = "Terraform Remote State"
}
object_key="instances/instances-${local.ami}.txt"
object_source="output.txt"
}