Skip to content

Commit

Permalink
Terraform CLI - Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeetninawe committed Jan 8, 2021
1 parent 85adb99 commit b144052
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
23 changes: 7 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"

name = "my-vpc"
cidr = "10.0.0.0/16"

azs = ["us-west-1b", "us-west-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
resource "aws_instance" "demo_vm_1" {
provider = aws.aws_west
ami = var.ami
instance_type = var.type

tags = {
Terraform = "true"
Environment = "dev"
name = "Demo VM 1"
}
}

resource "aws_instance" "demo" {
count = length(module.vpc.private_subnets)
resource "aws_instance" "demo_vm_2" {
provider = aws.aws_west
ami = var.ami
instance_type = var.type
vpc_security_group_ids = [module.vpc.default_security_group_id]
subnet_id = tolist(module.vpc.private_subnets)[count.index]

tags = {
name = "Demo VM ${count.index}"
name = "Demo VM 2"
}
}

Expand Down
9 changes: 6 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ variable "type" {
description = "Size of VM"
}

output "instance_id" {
//value = aws_instance.demo[*].id
value = [for b in aws_instance.demo : b.id]
output "instance_id_1" {
value = aws_instance.demo_vm_1.id
}

output "instance_id_2" {
value = aws_instance.demo_vm_2.id
}

0 comments on commit b144052

Please sign in to comment.