Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: create multiple resource in Variables #25

Open
Faarhad opened this issue Apr 6, 2023 · 1 comment
Open

[Question]: create multiple resource in Variables #25

Faarhad opened this issue Apr 6, 2023 · 1 comment
Labels
question Further information is requested

Comments

@Faarhad
Copy link

Faarhad commented Apr 6, 2023

Describe and write the question.

How to create multiple resources in scenario described in branch 007 (it was about creating resources using tfvars.
I mean more than 1 insurance in tfvars
Regards,

The logs if needed

No response

@Faarhad Faarhad added the question Further information is requested label Apr 6, 2023
@mohammadll
Copy link
Member

Hi , we can create multiple resources using Meta-arguments . I wrote two of them below

  • count
  • for_each

for example:

we want to create two instances with different machine_names using single "aws_instance" block

variables.tf:

variable "instance_names" {
type = map(string)
default = {
"instance1" = "babak"
"instance2" = "babak2"
}
}

main.tf:

resource "aws_instance" "aws_instances" {
for_each = var.instance_names
ami = var.ami_id
instance_type = var.instance_type
key_name = var.key_name

tags = {
Name = each.value
Created_By = "terraform"
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants