Hi ! I have to create a private connection (to the...
# google-cloud
k
Hi ! I have to create a private connection (to then deploy a cloudsql instance).
Copy code
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:
Copy code
* 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
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
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:
Copy code
__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
Sorry about that, it looks like in our examples for the Connection, the network might need to be the network.id
Copy code
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
So, with the following code:
Copy 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:
Copy code
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:
Copy code
$ 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
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
Damn, I was scared by this option ...
sure
Any way you suggest me to override this now ?
o
I'm not sure, I'm not familiar with this resource & options, sorry
k