[MUSIC PLAYING]
MARTIN OMANDER: Hi, Dina.
How are you?
DINA PORTMAN: I'm great.
I'm really excited for our pair programming session today.
MARTIN OMANDER: Yeah.
Development has really picked up here at Big Corp Limited
since we started these sessions.
What are we working on today, Dina?
DINA PORTMAN: Well, [SIGHS] it's kind of tricky,
and I'm not really sure how to do it.
My manager wants to launch a private internal wiki on GCP.
MARTIN OMANDER: Oh, what do you mean?
DINA PORTMAN: Well, she doesn't want
it to be accessible from the public internet.
MARTIN OMANDER: Oh, that doesn't sound so bad.
DINA PORTMAN: Well, the tricky part
is that she also wants our Cloud Function microservices to be
able to write to the wiki.
MARTIN OMANDER: Ah.
Sounds like we need to set up a serverless VPC connector.
We can host private applications,
like this wiki or even databases,
on virtual machines or clusters in Google Compute Engine.
And with a serverless VPC connecter,
we can connect to any of these private resources.
[MUSIC PLAYING]
All right.
Let's get back to the issue at hand, Dina.
To start, would you set up a private wiki
in Google Compute Engine?
DINA PORTMAN: OK, I'm ready.
MARTIN OMANDER: All right.
So if you click on the Navigation menu there, exactly,
and then click Marketplace.
And search for "mediawiki."
And the one I usually use is the one from--
yeah.
That's the one, yeah.
Let's set it up as a public service.
So this is all defaults throughout so we can test it.
DINA PORTMAN: OK.
OK.
So we're just going leave all of these just as they are
and Deploy.
MARTIN OMANDER: Very nice.
So this will take a few minutes.
DINA PORTMAN: Wow, that was easy.
MARTIN OMANDER: Yeah.
Let's give it a minute so the external IP
address will start working.
Now, on the upper right there, you see it's a Site Address.
That's the external IP address.
So paste that into your browser and test
if we can see this MediaWiki installation.
DINA PORTMAN: OK.
Hey, it works.
MARTIN OMANDER: Yeah, great.
Now let's update the network settings so that it no longer
has a public IP address.
So you can do that by clicking the Navigation menu,
upper left, and then go to Compute Engine.
And click your virtual machine-- should show up here.
Can you make the font a little bit bigger, Dina?
Thank you.
Easier for me to see.
So then scroll down to Network Interfaces.
DINA PORTMAN: OK.
MARTIN OMANDER: And there it is.
OK.
And for that one, click nic0 there.
Oh, sorry, click Edit at the top of the--
DINA PORTMAN: Oh, OK.
Go back.
MARTIN OMANDER: Yeah, sorry.
I gave the wrong instructions.
Yeah.
Now click the-- exactly-- little pen there.
And here it says, External IP.
We have an Ephemeral IP address.
So let's set this to None.
DINA PORTMAN: OK.
MARTIN OMANDER: This means we won't be able-- and Done.
And then Save at the bottom of the page.
Very good.
Let's give that a minute for the network change to take effect.
So we turned off the external ephemeral IP address.
Now check the network address for that MediaWiki
again from the public internet.
See if we can reach it.
DINA PORTMAN: Looks like it doesn't exist anymore.
Hm.
I'm going to try the private IP address.
MARTIN OMANDER: Oh, that's right.
It has a private internal one, as well.
DINA PORTMAN: Yeah.
Can I look at that one?
Hm.
This one also doesn't work.
MARTIN OMANDER: Perfect.
This is just what we wanted.
So this MediaWiki instance still exists,
but it's off of the public internet.
These network settings will work with any kind
of private service or infrastructure
that we might want to set up.
Now it's a MediaWiki, but it could
be a mail server or, say, a MongoDB instance
or something like it.
OK.
Now we're going to connect to it.
So next, we'll set up the connector.
Would you go back to Cloud Console
and click that Navigation menu?
And then go to VPC Network, and Serverless VPC Connector.
Perfect.
And let's Create a new connector there at the top.
DINA PORTMAN: OK.
Connector.
What settings should I use?
MARTIN OMANDER: Let's go with the defaults.
DINA PORTMAN: OK.
I'm just going to copy this one that they give here.
MARTIN OMANDER: Mhm.
DINA PORTMAN: OK.
MARTIN OMANDER: Excellent.
Now we have a VPC connector that we can access from serverless.
So for the final step, let's set up
a Cloud Function, which will use this VPC connector to access
the MediaWiki itself.
So go to Cloud Functions.
DINA PORTMAN: OK.
Create a new function.
MARTIN OMANDER: Sounds good.
DINA PORTMAN: What kind of function should it be?
MARTIN OMANDER: For now, let's go with the HTTP Trigger Type.
So we will use the browser to trigger this function,
and then this function will access the hidden MediaWiki
server.
DINA PORTMAN: OK, sounds good.
Do I need to worry about any of these settings down here?
MARTIN OMANDER: Oh, right.
Good thing you noticed.
In the Advanced sections, would you go to Connections
and select the new serverless connector
that you just created?
DINA PORTMAN: Cool.
MARTIN OMANDER: Yeah, and this will
ensure that all traffic from the Cloud Function--
all outbound network calls from this Cloud Function--
will go through this private connector that you just set up.
DINA PORTMAN: OK.
So if it's using the private connection,
that means it will be able to reach that private IP
address for the wiki.
MARTIN OMANDER: Yep, that's correct.
DINA PORTMAN: OK, cool.
Well, then, I'm going to put that private address
into our function.
I'm going to grab it from here.
MARTIN OMANDER: Mhm.
DINA PORTMAN: OK, I'm going to deploy.
So to say what I just did, I put the private address
into our function here.
And then we're going to trigger the function
by accessing the URL, which will then
call the REST API of the MediaWiki server
using the private IP address.
Right?
MARTIN OMANDER: Yeah, perfect.
Yeah, that sounds great.
Let's deploy the function.
This will take a few minutes.
Cool.
So now let's test it.
Go to the HTTP Trigger address of this function.
And by doing that, you're calling the function.
And the function, in turn, calls the wiki REST API.
DINA PORTMAN: It works.
Huzzah!
Oh, you were right.
It wasn't so tricky after all.
MARTIN OMANDER: Another successful pair programming
session for Big Corp Limited.
DINA PORTMAN: At this rate, we're
going to have to rename it Big Corp Unlimited.
MARTIN OMANDER: [LAUGHS]
[MUSIC PLAYING]