data source using for_each

244 views
Skip to first unread message

Krishna Nag

unread,
Jun 19, 2021, 3:58:26 AM6/19/21
to Terraform
i need to get app service plan id's using the data source and use these to create app services.

 i am getting the id if it is single value.


data "azurerm_app_service_plan" "aspnameid" {
  for_each = { for n in var.appservice_plan : n.appservice_plan_name => n }
 name                = each.value.appservice_plan_name
  resource_group_name = var.resource_group_name

   depends_on = [
   module.root_appserviceplan
   ]
}

i was trying use it as below  #appservice_plan_id                  = data.azurerm_app_service_plan.asp_id[each.value.asp_name].id

but this is not working for me. any ideal solution to get multiple app service plan ids and use in creating multiple app services. Thanks

Fernando 🐼

unread,
Jun 19, 2021, 6:31:23 AM6/19/21
to terrafo...@googlegroups.com
I assume your for each is the same index? 

--
Fernando 🐼

--
In the coming weeks, inbound messages to this group will be disabled, and it will be used for outbound announcements only. To prepare for this switch, please direct questions and conversations to our primary medium to communicate with practitioners: https://discuss.hashicorp.com/c/terraform-core/27. We look forward to collaborating with you there!
 
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/a69435ee-79b7-4337-bf4d-8832f2ca0823n%40googlegroups.com.

Krishna Nag

unread,
Jun 19, 2021, 10:51:07 AM6/19/21
to terrafo...@googlegroups.com
Sorry

i did not get what you mentioned her  "for_each same index"

Thanks



--
Regards,
Krishna Nagubadi

Fernando 🐼

unread,
Jun 19, 2021, 10:52:03 AM6/19/21
to terrafo...@googlegroups.com
Can you share your code.? 

--
Fernando 🐼

Alexandra Freeman

unread,
Jun 21, 2021, 10:32:23 AM6/21/21
to Terraform
Hello and thank you for your question!
On June 3, 2019 HashiCorp launched Discuss, a forum to facilitate dialogue within the HashiCorp community. This format allows answers to be more readily searched and indexed, making it easier to find answers to existing questions and to share knowledge with each other. Please direct all questions and conversations to the discussion forum. We look forward to collaborating with you there!

Cheers!

Krishna Nag

unread,
Jun 21, 2021, 10:57:44 AM6/21/21
to terrafo...@googlegroups.com
Hi 

end up using count and it worked

Reply all
Reply to author
Forward
0 new messages