Skip to content

Instantly share code, notes, and snippets.

@kunduso
Last active November 8, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunduso/ef1b1c2c2e4c8791563d1eadf7e1343c to your computer and use it in GitHub Desktop.
Save kunduso/ef1b1c2c2e4c8791563d1eadf7e1343c to your computer and use it in GitHub Desktop.
# string variable declare
variable "region" {
description = "The region where to provision resources"
type = string
default = "us-west-2"
}
# string variable usage
provider "aws" {
region = var.region # this will assign the value "us-west-2" to region
access_key = var.access_key
secret_key = var.secret_key
}
#----------------------------------------------------------------------------
# list variable declare
variable "bucket_name" {
description = "The name of S3 bucket"
type = list(string)
default = ["beans", "pepper", "tomato"]
}
# list variable usage
resource "aws_s3_bucket" "aws-b1" {
bucket = "${var.bucket_name[count.index]}-${random_integer.rand_int.result}"
acl = "private"
count = 3
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
#----------------------------------------------------------------------------
#map variable declare
variable "ami_location" {
type = map
default = {
us-east-1 = "ami-0412e100c0177fb4b"
us-east-2 = "ami-0354df7841220296c"
}
}
#map variable usage
resource "aws_instance" "server" {
ami = "${var.ami_location["${var.region}"]}"
instance_type = "t2.micro"
key_name = "terraform-key"
security_groups = ["${aws_security_group.allow_rdp.name}"]
tags = {
Name = "Web-App-Prod-1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment