So, I have a situation where I have a DNS register...
# google-cloud
g
So, I have a situation where I have a DNS registered to project A and it is setup there into a DNS zone. All fine. Now I also have a project B where I have a GKE running and it has an ingress. I want to bind this domain to that ingress IP address without having to do copy-pasting addresses over to different codebases. My initial thoughts on this are: 1. Read the other project state file and deduct the IP address from there. But as far as I have understood this is not possible but can only be done over different stacks? 2. Retrieve the managed cluster object via
gcp.container.getCluster
and proceed from there to get the ingress. I do not see however an immediate logical way to proceed to get the ingress object and its IP via this route 3. Bind the domain on project B cluster definition via its
dnsConfig
attribute but I think this won't work and would only work on the same project? 4. Bite the bullet and just do copy-pasting over. Not happy if I have to do this but might be the only reasonable choice
Oh, I'm an idiot. Of course one would have to fetch the load balancer not the ingress 🤦‍♂️
Didn't find an easy way to do this. I find it astonishing that Pulumi still doesn't support referencing another project state but it does support this for terraform remote states? Like, what. I ended up downloading the another project state file via custom code, parsing that and finding the correct resource and from its outputs get the IP address value. Nuts but works.
Did it like this. Yes, it is a hack, yes, I do feel dirty, yes, it can break. But until I can figure out a better way I'm going with this:
Copy code
const project = pulumi.output(gcp.projects.getProject({ filter: "name:project-with-state-name" }));

const stackStateContent = project.apply(project => new storage.Storage({
  projectId: project.id
})).apply(stor => stor
  .bucket("pulumi-state")
  .file("rootFolderName/.pulumi/stacks/stackname.json")
  .download())
  .apply(downloadResult => JSON.parse(downloadResult.toString()));

const ingressIp = liveDevStackStateContent.apply(stackState => {
  const resources : Array<any> = stackState.checkpoint.latest.resources;
  const ingressResource = resources.find((res : any) => res.id === "web/web-ingress");
  const ip : string = ingressResource.outputs.status.loadBalancer.ingress[0].ip;
  return ip;
});
Any better ideas are welcome!