https://pulumi.com logo
Title
k

kind-keyboard-17263

05/27/2022, 2:30 PM
Hi ! I have to create a private connection (to then deploy a cloudsql instance).
vpc = gcp.compute.Network(
    "default",
    name="default",
    project=project,
    auto_create_subnetworks=False,
    routing_mode="GLOBAL")

ipv4_address = gcp.compute.GlobalAddress(
  "ipv4-address",
  address="192.168.3.1",
  description="IP address range to be used for private connection",
  network=vpc.id,
  project=project,
  address_type="INTERNAL",
  purpose="PRIVATE_SERVICE_CONNECT",  # Correct ?
)

private_vpc_peering = gcp.servicenetworking.Connection(
  "private-vpc-peering",
  network="default",
  service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
  reserved_peering_ranges=[ipv4_address.name]
)
When I execute this, I see this very cryptic error:
* Failed to find Service Networking Connection, err: Failed to retrieve network field value, err: project: required field is not set
I don't really understand the meaning of the error 😅 ! Thanks for help
o

orange-policeman-59119

05/27/2022, 2:39 PM
Hey there! It looks like you either need to set the
gcp:project
config value for your stack or add project to the constructor for the Connection resource named "private-vpc-peering".
k

kind-keyboard-17263

05/27/2022, 2:42 PM
I have the gcp:project correctly configured (this is just a tiny part of the script) and also, I have added a project=<project> to the constructor, but:
__self__._internal_init(resource_name, *args, **kwargs)
    TypeError: _internal_init() got an unexpected keyword argument 'project'
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
(Thanks for the super quick answer anyway 🙏 )
o

orange-policeman-59119

05/27/2022, 3:21 PM
Sorry about that, it looks like in our examples for the Connection, the network might need to be the network.id
import pulumi
import pulumi_gcp as gcp

peering_network = gcp.compute.Network("peeringNetwork")
private_ip_alloc = gcp.compute.GlobalAddress("privateIpAlloc",
    purpose="VPC_PEERING",
    address_type="INTERNAL",
    prefix_length=16,
    network=peering_network.id)
foobar = gcp.servicenetworking.Connection("foobar",
    network=peering_network.id,
    service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
    reserved_peering_ranges=[private_ip_alloc.name])
Could you try setting the network property to "vpc.id"? If that doesn't work, or either way really, it seems like an area in which we could improve our diagnostics so that the error points you in the right direction. https://www.pulumi.com/registry/packages/gcp/api-docs/servicenetworking/connection/
k

kind-keyboard-17263

05/27/2022, 3:25 PM
So, with the following code:
vpc = gcp.compute.Network(
    "default",
    name="default",
    project=project,
    auto_create_subnetworks=False,
    # to allow vpn broadcasting routes
    routing_mode="GLOBAL")


ipv4_address = gcp.compute.GlobalAddress(
  "ipv4-address",
  description="IP address range to be used for private connection",
  network=vpc.id,
  project=project,
  address_type="INTERNAL",
  purpose="PRIVATE_SERVICE_CONNECT",  # Correct ?
)

private_vpc_peering = gcp.servicenetworking.Connection(
  "private-vpc-peering",
  network=vpc.id,
  service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
  reserved_peering_ranges=[ipv4_address.name],
)
I have:
error: 1 error occurred:
        * Error waiting for Create Service Networking Connection: Error code 9, message: Allocated IP range 'ipv4-address-f7f5e3e' not found in network.
    Help Token: xxx
And if I run:
$ gcloud compute addresses  list
NAME                                    ADDRESS/RANGE  TYPE      PURPOSE                  NETWORK  REGION       SUBNET  STATUS
ipv4-address-f7f5e3e                    192.168.3.1    INTERNAL  PRIVATE_SERVICE_CONNECT  default                       RESERVED
xxx  35.226.82.209  EXTERNAL  NAT_AUTO                          us-central1          IN_USE
Sorry ^ fixed the output of the command 🙂
o

orange-policeman-59119

05/27/2022, 3:27 PM
Oh, this looks like it could be a bug in our provider or upstream of us.
Could you create an issue on this repo? github.com/pulumi/pulumi-gcp
k

kind-keyboard-17263

05/27/2022, 3:27 PM
Damn, I was scared by this option ...
sure
Any way you suggest me to override this now ?
o

orange-policeman-59119

05/27/2022, 3:39 PM
I'm not sure, I'm not familiar with this resource & options, sorry
k

kind-keyboard-17263

05/27/2022, 3:41 PM