This message was deleted.
# getting-started
s
This message was deleted.
p
I can share a working solution in python if you want 🙂
Copy code
ip_address_range = gcp.compute.GlobalAddress(
    "global-address",
    purpose="VPC_PEERING",
    address_type="INTERNAL",
    prefix_length=16,
    network=network.name,
)
gcp.servicenetworking.Connection(
    "private-connection",
    network=network.id,
    service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
    reserved_peering_ranges=[ip_address_range.name],
)
where
network
is an instance of
gcp.compute.Network
👏 1
👀 1
Make sure you have
<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>
service enabled. If you want to make it via pulumi as well:
Copy code
service_networking_api = gcp.projects.Service(
    "servicenetworking",
    disable_dependent_services=True,
    service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
)
However then you’ll need to explicitly add
depends_on
in
gcp.servicenetworking.Connection
(or run
pulumi up
twice 😛):
Copy code
gcp.servicenetworking.Connection(
        "private-connection",
        network=network.id,
        service="<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>",
        reserved_peering_ranges=[ip_address_range.name],
=>      pulumi.ResourceOptions(depends_on=[service_networking_api])
    )
h
and while creating cloudsql private instance we can use this service connection right...in that way cloud sql private IP is in the range of
allocated_range
p
If you want to use private IP in CloudSQL, project must have at least one private connection declared. The code above should satisfy that requirement.
Setting private IP on cloudsql instance itself is pretty straighforward:
Copy code
...
ip_configuration=gcp.sql.DatabaseInstanceSettingsIpConfigurationArgs(
    private_network=network.id,
),
...
and again (unfortunately), the dependency between
gcp.servicenetworking.Connection
and
gcp.sql.DatabaseInstance
cannot be detected automatically, so you either have to make sure that private connection is created before you try to create database instance or use
depends_on
again to explicitly mark this fact
👏 1
🙌 1
w
thanks! just catching up and reading everything
ok, that all makes sense. wouldn't have thought globaladdress was what I was looking for, as for the dependency checks, @helpful-hair-30515 good case for splitting it out into its own class and doing the checks there (against the config)
👍 1
👏 1
p
In my project, I created two stacks. One creates the project, VPC with private connection and enables all required APIs. The second one uses StackReference to get VPC name and creates other resources such as CloudSQL, Memorystore Redis etc.
h
Thanks @prehistoric-activity-61023 I tried to understand it, if we do it in console there is actually two steps as you codified already
1.allocate IP range
2.Create Connection
@wooden-battery-52855 that should work as well and as @prehistoric-activity-61023 mentioned to use stack references instead also a great choice!!!