Skip to content

Instantly share code, notes, and snippets.

@kunduso

kunduso/TerraformVariablesUsage.tf Secret

Last active Nov 8, 2020
Embed
What would you like to do?
# 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