# Automated Installation on Google Cloud Platform (GCP)

{% embed url="<https://vimeo.com/1015037879>" %}

Navigate to Compute Engine > VM instances and hit the `+ CREATE INSTANCE` button as usual, then select Name, Region, Machine configuration etc.

Expand `Advanced options` at the bottom of the page:

<div align="left"><figure><img src="https://2080310565-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxDhnoLkxryJhtCjj7mE2%2Fuploads%2Fgit-blob-2dc26fcd70ecbd3091b70c9b47ef2375c8ab00d0%2FGCP_Advanced_options.PNG?alt=media" alt=""><figcaption></figcaption></figure></div>

Then scroll down and expand `Management`:

<div align="left"><figure><img src="https://2080310565-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxDhnoLkxryJhtCjj7mE2%2Fuploads%2Fgit-blob-01f13c6eba1bc8df2c0b4176fbabbba41c7e7283%2FGCP_Management.PNG?alt=media" alt=""><figcaption></figcaption></figure></div>

In the `Automation` section paste in your customised startup script like:

```bash
#!/bin/bash
# Modify these lines to set the installation specific variables
ATCLIENT="@democlient"
ATDEVICE="@demodevice"
DEVNAME="cloudvm1"
OTP="739128"
USER="noports"
# The rest of the script shouldn't be changed
useradd ${USER}
export HOME="/home/${USER}"
export SUDO_USER="${USER}"
mkdir -p /run/atsign
cd /run/atsign
VERSION=$(wget -q -O- "https://api.github.com/repos/atsign-foundation/noports/releases/latest" | grep -Po '"tag_name": "v\K.*?(?=")')
wget https://github.com/atsign-foundation/noports/releases/download/v${VERSION}/universal.sh
sh universal.sh -t device -c ${ATCLIENT} -d ${ATDEVICE} -n ${DEVNAME}
/usr/local/bin/at_activate enroll -a ${ATDEVICE} -s ${OTP} -p noports -k /home/${USER}/.atsign/keys/${ATDEVICE}_key.atKeys -d ${DEVNAME} -n "sshnp:rw,sshrvd:rw"
chown -R ${USER}:${USER} /home/${USER}
```

NB this script is creating a new user `noports` to deal with the fact that GCP images don't have default usernames.

Once filled, the box should look something like:

<div align="left"><figure><img src="https://2080310565-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxDhnoLkxryJhtCjj7mE2%2Fuploads%2Fgit-blob-427faf971962da8730c0b17c97ca7254defa1a49%2FGCP_Startup_script.PNG?alt=media" alt=""><figcaption></figcaption></figure></div>

The VM is now ready for `Create`

After a few minutes the APKAM key can be approved:

```
at_activate approve -a @demodevice --arx noports --drx cloudvm1
```

If the VM isn't quite ready you'll see:

```
Found 0 matching enrollment records
No matching enrollment(s) found
```

Waiting a little longer and retrying should produce a successful approval:

```
Found 1 matching enrollment records
Approving enrollmentId 0bd3613d-d3e2-45b3-b175-8cab06c9bad0
Server response: AtEnrollmentResponse{enrollmentId: 0bd3613d-d3e2-45b3-b175-8cab06c9bad0, enrollStatus: EnrollmentStatus.approved}
```

The VM is now ready for connection with the NoPorts client.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.noports.com/installation/cloud-installation-guides/automated-installation-on-google-cloud-platform-gcp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
