I am using Google Cloud Run with Pulumi (similar to Terraform). My setup for Cloud Run's domain mapping is:
new gcp.cloudrun.DomainMapping(
`${prefix}-domain-mapping`,
{
location,
name: 'xxx',
metadata: {
namespace: projectId,
},
spec: {
routeName: appService.name,
},
},
{
dependsOn: [appService],
},
)
Where appService
points to an instance of Cloud Run service. This successfully creates a domain mapping to the Cloud Run service.
Next I am setting up a DNS zone with records:
const zone = new gcp.dns.ManagedZone(`${prefix}-zone`, {
name: `${prefix}-zone`,
dnsName: 'xxx.',
visibility: 'public',
})
const ips = ['xxx', 'xxx', 'xxx', 'xxx']
new gcp.dns.RecordSet(
`${prefix}-a-records`,
{
name: 'xxx.',
managedZone: zone.name,
type: 'A',
ttl: 3600,
rrdatas: ips,
},
{
dependsOn: [zone],
deleteBeforeReplace: true,
},
)
The code above works. I have a DNS zone with four A records pointing to 4 different IP-addresses, which point to a Cloud Run service. My problem is this: how do I automate the IPs, which I have hard-coded above? I want the IP-addresses of Cloud Run to be dynamically set for the A records. The ips
variable has to point to the Cloud Run instance's IPs, but I can't find a way to do that.
Or perhaps I'm doing this all wrong and there's another way this should be done? My goal is that if the Cloud Run service is updated and receives new IPs, the DNS records should be automatically updated as well. I don't want to manually update addresses.
Since Pulumi is more or less equivalent to Terraform, answers in either Terraform or Pulumi are greatly appreciated!