Created
March 11, 2019 05:59
-
-
Save kaitoii11/7bb506da34f94e10484f373ee0755186 to your computer and use it in GitHub Desktop.
Terraform example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
access_key = "<ACCESS KEY>" | |
secret_key = "<SECRET KEY>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
access_key = "${var.access_key}" | |
secret_key = "${var.secret_key}" | |
region = "${var.region}" | |
} | |
resource "aws_instance" "example" { | |
ami = "${lookup(var.amis, var.region)}" | |
instance_type = "t2.micro" | |
provisioner "local-exec" { | |
command = "echo ${aws_instance.example.public_ip} > ip_address.txt" | |
} | |
} | |
resource "aws_eip" "ip" { | |
instance = "${aws_instance.example.id}" | |
} | |
output "ip" { | |
value = "${aws_eip.ip.public_ip}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "access_key" {} | |
variable "secret_key" {} | |
variable "region" { | |
default = "us-east-1" | |
} | |
variable "amis" { | |
type = "map" | |
default = { | |
"us-east-1" = "ami-b374d5a5" | |
"us-west-2" = "ami-4b32be2b" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with
terraform apply -var-file="secret.tfvars