broad-parrot-2692
03/10/2023, 9:00 PMforEach
loop to setup my DNS zones in GCP, and I just realized that if I'm going to create DNS records in these zones, I need to actually work with the output. I need to somehow appropriately chain the resource dependencies so the order of operations are correct. I started going down the road of using eval
to dynamically declare the const, and that was when I realized I should probably consult with others and see if anyone has advice to give.
Thank you in advanced!billowy-army-68599
03/10/2023, 9:03 PMbroad-parrot-2692
03/10/2023, 9:05 PMthis should work okay, what do you want the end result to be?Thank you for taking the time to respond! The above codeblock works just fine, the problem is I now need to create A records in this zone, and that involves referencing the zone I've just created. I could just type the name of the zone as a string, but then the dependency chain would be broken.
also - you might want to make this a component!I will look into this! I'm not immediately sure what you mean though
billowy-army-68599
03/10/2023, 9:07 PMbroad-parrot-2692
03/10/2023, 9:09 PMAh, i see, do you want to add different records to each zone, so you want to have them stored that way?I'm sorry, I'm having a little trouble understanding what you mean by "So you want to have them stored that way". I do want to add a variety of DNS records to each zone. Should I just manually declare the dependency? It seems like the wrong thing to do since I do need the output from the zone declaration, so I might as well be looking for ways to capture the output from the
forEach
loop. I'll definitely be running into this problem laterbillowy-army-68599
03/10/2023, 9:13 PMzones.forEach((zone) => {
// somehow declare const here to work with the output zone name and establish deps?
const myZone = new gcp.dns.ManagedZone(zone.name, zone.args, zone.opts);
new gcp.dns.RecordSet("foo", {
name: "<http://foo.nuggies.life|foo.nuggies.life>"
managedZone: myZone.id
type: "A",
ttl: 300,
rrdatas: ["8.8.8.8"],
});
}
append
or such like in the forEach
broad-parrot-2692
03/10/2023, 9:14 PMconst myZone
be set twice? (one per zone created)billowy-army-68599
03/10/2023, 9:15 PMbroad-parrot-2692
03/10/2023, 9:16 PMyou can just append the id to a new data structure and loop over thatThis makes sense! My brain has been pretty fried over this for a minute, but that should work perfectly.
billowy-army-68599
03/10/2023, 9:28 PMbroad-parrot-2692
03/11/2023, 1:31 AM