Get IP address from Azure Private Endpoint using Pulumi TypeScript API

470 Views Asked by At

I have a Private Endpoint created in my Azure subscription. If I look into the Azure Portal I can see that the private IP assigned to my Private Endpoint NIC is 10.0.0.4.

enter image description here

But how can I get the IP address value using the Pulumi TypeScript API, so I can use it in my scripts?

const privateEndpoint = new network.PrivateEndpoint("privateEndpoint", {
    privateLinkServiceConnections: [{
        groupIds: ["sites"],
        name: "privateEndpointLink1",
        privateLinkServiceId: backendApp.id,
    }],
    resourceGroupName: resourceGroup.name,
    subnet: {
        id: subnet.id,
    }
});

export let ipc = privateEndpoint.networkInterfaces.apply(networkInterfaces => networkInterfaces[0].ipConfigurations)
console.log(ipc)

This is the current output for that ipc variable:

    OutputImpl {
      __pulumiOutput: true,
      resources: [Function (anonymous)],
      allResources: [Function (anonymous)],
      isKnown: Promise { <pending> },
      isSecret: Promise { <pending> },
      promise: [Function (anonymous)],
      toString: [Function (anonymous)],
      toJSON: [Function (anonymous)]
    }
2

There are 2 best solutions below

1
On

You can't log a pulumi Output until its resolved, so if you change your code slightly, this will work:

const privateEndpoint = new network.PrivateEndpoint("privateEndpoint", {
    privateLinkServiceConnections: [{
        groupIds: ["sites"],
        name: "privateEndpointLink1",
        privateLinkServiceId: backendApp.id,
    }],
    resourceGroupName: resourceGroup.name,
    subnet: {
        id: subnet.id,
    }
});

export let ipc = privateEndpoint.networkInterfaces.apply(networkInterfaces => console.log(networkInterfaces[0].ipConfigurations))
0
On

I found the solution to my problem.

I was publishing a Static Web App to an incorrect Private DNS Zone. Correct one should be privatelink.1.azurestaticapps.net.

Once that was fixed I got the data that I needed.

    {
      name: 'config1',
      privateDnsZoneId: '/subscriptions/<subscription>/resourceGroups/rg-static-webappc0811aae/providers/Microsoft.Network/privateDnsZones/privatelink.1.azurestaticapps.net',
      recordSets: [
        {
          fqdn: 'thankful-sand-084c7860f.privatelink.1.azurestaticapps.net',
          ipAddresses: [Array],
          provisioningState: 'Succeeded',
          recordSetName: 'thankful-sand-084c7860f',
          recordType: 'A',
          ttl: 10
        }
      ]
    }
    {
      fqdn: 'thankful-sand-084c7860f.privatelink.1.azurestaticapps.net',
      ipAddresses: [ '10.0.0.4' ],
      provisioningState: 'Succeeded',
      recordSetName: 'thankful-sand-084c7860f',
      recordType: 'A',
      ttl: 10
    }