Hello! I just finished writing this adorable litt...
# typescript
b
Hello! I just finished writing this adorable little
forEach
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!
b
this should work okay, what do you want the end result to be?
also - you might want to make this a component!
b
this 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
b
Ah, i see, do you want to add different records to each zone, so you want to have them stored that way?
b
I added a bit to the bottom of the script I posted earlier to hopefully give more insight into the problem I'm running into... I probably should have included that portion in the first place
Ah, 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 later
b
this should work fine
Copy code
zones.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"],
});
}
if you want to store the zone id for each created zone you should just be able to do an
append
or such like in the
forEach
(sorry for the bad formatting)
b
In that script, wouldn't
const myZone
be set twice? (one per zone created)
oh I see you have the DNS record created inside the foreach loop.
Because the relationship of zones to DNS records is not 1:1, I don't think that would work for my use-case...
b
it would get overridden on each loop, but you’re creating the record inside the loop too. If you want to create records outside the loop, you can just append the id to a new data structure and loop over that
let me throw together an example, give me a few
b
you can just append the id to a new data structure and loop over that
This makes sense! My brain has been pretty fried over this for a minute, but that should work perfectly.
Thank you again for taking the time to respond to my question and help me with this, I really appreciate it!😸
b
example! https://github.com/jaxxstorm/pulumi-examples/blob/main/typescript/aws/multiple_buckets/index.ts Couple of different ways to approach it, but ultimately you’re just storing data for later use
b
This is what I ended up doing; thank you again for helping me find a solution meow party