Legacy Dev Forum Posts

 View Only

Sign Up

Nested loops for schedule and schedule_groups

  • 1.  Nested loops for schedule and schedule_groups

    Posted 06-05-2025 18:26

    VernonVanDam | 2023-05-15 00:28:54 UTC | #1

    Hi,

    I'm create a terraform project to create a list of schedules and schedule groups using csv as the source data. The output ids of the schedule module feeds the input of the schedule_groups module. I created the basic logic in the code below:

    What I'm trying to accomplish is to create a list of schedule ids that are to be assigned to a schedule-group.

    The basic logic is here:

    locals {

    all-schedule-ids = { "AustraliaDay" = "49fa57ec-283d-4499-aa59-1a3c67303828" "BoxingDay" = "d36ccc3a-bd8c-425b-87d1-3f40606424da" "ChristmasDay" = "cf983444-283c-4c1e-8513-1ecd40f1b86f" "NewYearsDay" = "889fe41e-c957-4ecb-bb66-0c8f53810fcd" "OPEN24x7" = "c941592d-7b92-4a12-851d-b6034537be6e" "SALES800AM-7PM-M-FClosed" = "290a8963-133a-4101-9090-48eab09f0426" "SALES800AM-7PM-M-FOpen" = "a69f6244-bb4a-4d1a-8c7a-f03941517071" "SALES900AM-5PM-SClosed" = "0735f206-54f3-4874-8ca9-1e9f81e902e4" "SALES900AM-5PM-SOpen" = "cb9ec105-cbbc-476d-b1a0-31798f635403" "SALESEARLYCLOSE" = "73c473c4-a777-4234-a542-fb8c83db328e" "SERVICE800AM-7PM-M-FOpen" = "730bb23d-aeb4-424e-907b-159a4542b21f" "SERVICE900AM-5PM-SClosed" = "7b725b21-e492-419f-92f0-f7ecb3fca578" "SERVICE900AM-5PM-SOpen" = "3916c47f-d411-45ab-9c87-29dcc887eec5" "SERVICEEARLYCLOSE" = "e919981c-5667-4ddc-83ba-64c4d395fb6e"

    }

    sg-sales-open = ["SALES800AM-7PM-M-FOpen", "SALES900AM-5PM-SOpen"] sg-sales-closed = ["SALES800AM-7PM-M-FClosed"] sg-sales-holiday = ["ChristmasDay", "AustraliaDay"]

    sg-service-open = ["SERVICE900AM-5PM-SOpen", "SERVICE800AM-7PM-M-FOpen"] sg-service-closed = ["SERVICE900AM-5PM-SClosed"] sg-service-holiday = ["BoxingDay", "AustraliaDay"]

    schedule-ids-list1 = [ for k,v in local.all-schedule-ids : v if k == "OPEN24x7" ] schedule-ids-list2 = [ for k,v in local.all-schedule-ids : v if k == local.sg-sales-open[*]] schedule-ids-list3 = [ for k,v in local.all-schedule-ids : v if k == ([ for x,y in local.sg-sales-open: y ]) ] schedule-ids-list4 = [ v for k, v in local.allschedule-ids if k in local.sg-sales-open ] schedule-ids-map = [ for k,v in local.all-schedule-ids : v if k == [for day in local.sg-sales-open: day] ]

    }

    output "schedule-ids-list1" { value = local.schedule-ids-list1 }

    output "schedule-ids-list2" { value = local.schedule-ids-list2 }

    output "schedule-ids-list3" { value = local.schedule-ids-list3 }

    output "schedule-ids-list4" { value = local.schedule-ids-list4 }

    schedule-ids-list1 works fine schedule-ids-list2,3 & 4 are variants that I've tried to loop through the schedule-ids and return the id value if the key in the map matches any value in the sg-sales-open list. schedule-ids-map is incorrect syntax but contains the logic I'm looking for

    Any ideas?

    Output should look like this: schedule-ids-list = ["a69f6244-bb4a-4d1a-8c7a-f03941517071","cb9ec105-cbbc-476d-b1a0-31798f635403"]


    This post was migrated from the old Developer Forum.

    ref: 19902