File tree Expand file tree Collapse file tree 3 files changed +61
-29
lines changed Expand file tree Collapse file tree 3 files changed +61
-29
lines changed Original file line number Diff line number Diff line change 1- terraform {
2- required_providers {
3- aws = {
4- source = " hashicorp/aws"
5- version = " ~> 3.0"
6- }
7- }
8- }
9-
10- provider "aws" {
11- region = var. region
12- }
1+ // Using for_each meta-argument
132
14- variable "region" {
15- default = " us-west-1"
16- description = " AWS Region"
17- }
3+ resource "aws_instance" "demo" {
4+ for_each = {
5+ fruit = " apple"
6+ vehicle = " car"
7+ continent = " Europe"
8+ }
9+ provider = aws. aws_west
10+ ami = var. ami
11+ instance_type = var. type
1812
19- variable "ami" {
20- default = " ami-00831fc7c1e3ddc60 "
21- description = " Amazon Machine Image ID for Ubuntu Server 20.04 "
13+ tags = {
14+ name = " ${ each . key } : ${ each . value } "
15+ }
2216}
2317
24- variable "type" {
25- default = " t2.micro"
26- description = " Size of VM"
27- }
18+ /*
19+ Using count meta-argument
2820
2921resource "aws_instance" "demo" {
30- ami = var. ami
22+ count = 3
23+ provider = aws.aws_west
24+ ami = var.ami
3125 instance_type = var.type
3226
3327 tags = {
3428 name = "Demo System"
3529 }
3630}
37-
38- output "instance_id" {
39- value = aws_instance. demo . id
40- }
41-
31+ */
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_providers {
3+ aws = {
4+ source = " hashicorp/aws"
5+ version = " ~> 3.0"
6+ }
7+ }
8+ }
9+
10+ provider "aws" {
11+ alias = " aws_west"
12+ region = var. region_west
13+ }
14+
15+ provider "aws" {
16+ alias = " aws_east"
17+ region = var. region_east
18+ }
Original file line number Diff line number Diff line change 1+ variable "region_west" {
2+ default = " us-west-1"
3+ description = " AWS West Region"
4+ }
5+
6+ variable "region_east" {
7+ default = " us-east-1"
8+ description = " AWS East Region"
9+ }
10+
11+ variable "ami" {
12+ default = " ami-00831fc7c1e3ddc60"
13+ description = " Amazon Machine Image ID for Ubuntu Server 20.04"
14+ }
15+
16+ variable "type" {
17+ default = " t2.micro"
18+ description = " Size of VM"
19+ }
20+
21+ output "instance_id" {
22+ // value = aws_instance.demo[*].id
23+ value = [for b in aws_instance . demo : b . id ]
24+ }
You can’t perform that action at this time.
0 commit comments