<commit_before>---
title: Deploying BOSH on GCP
owner: Release Integration
---

<strong><%= modified_date %></strong>

This topic describes how to use the [bosh-bootloader](https://github.com/cloudfoundry/bosh-bootloader) command-line tool to set up an environment for Cloud Foundry on Google Cloud Platform (GCP) and deploy a [BOSH Director](https://bosh.io/docs/bosh-components.html#director). 

## <a id='overview'></a>Overview

After completing this topic, you will have the following:

1. A BOSH Director instance in the Availability Zone (AZ) of your choice
1. A set of randomly generated BOSH Director credentials
1. A generated key pair that allows you to SSH into the BOSH Director and any instances that BOSH deploys
1. A copy of the manifest you use to deploy the BOSH Director 
    <p class="note"><strong>Note</strong>: A <a href="https://bosh.io/docs/deployment-manifest.html">manifest</a> is a YAML file that defines the components and properties of a BOSH deployment.</p>
1. A basic cloud config 
    <p class="note"><strong>Note</strong>: A <a href="https://bosh.io/docs/cloud-config.html">cloud config</a> is a YAML file that defines IaaS-specific configuration for BOSH.</p>
1. A set of load balancers
    <p class="note"><strong>Note</strong>: bosh-bootloader creates the load balancers, but you must still configure DNS to point your domains to the load balancers. See the <a href="../common/dns_prereqs.html">Setting Up DNS for Your Environment</a> topic for more information.</p>

## <a id='downloads'></a> Step 1: Download Dependencies

Perform the following steps to download the required dependencies for bosh-bootloader:

1. Download [Terraform](https://www.terraform.io/downloads.html) v0.9.1 or later. Unzip the file and move it to somewhere in your PATH:
    <pre class="terminal">
    $ tar xvf ~/Downloads/terraform*
    $ sudo mv ~/Downloads/terraform /usr/local/bin/terraform
    </pre> 

1. Download the [BOSH CLI v2](https://bosh.io/docs/cli-v2.html#install). Make the binary executable and move it to somewhere in your PATH:
    <pre class="terminal">
    $ chmod +x ~/Downloads/bosh-cli-*
    $ sudo mv ~/Downloads/bosh-cli-* /usr/local/bin/bosh
    </pre>

1. Perform one of the following procedures to download and install bosh-bootloader:
    * On Mac OS X, use Homebrew:
        <pre class="terminal">$ brew install cloudfoundry/tap/bbl</pre>
    * Download the latest bosh-bootloader from [GitHub](https://github.com/cloudfoundry/bosh-bootloader/releases/latest). Make the binary executable and move it to somewhere in your PATH:
        <pre class="terminal">
        $ chmod +x ~/Downloads/bbl-*
        $ sudo mv ~/Downloads/bbl-* /usr/local/bin/bbl
        </pre> 

1. Download and install the [gcloud CLI](https://cloud.google.com/sdk/downloads).

## <a id='create-iam'></a> Step 2: Create an IAM Service Account

Perform the following steps to create the Identity and Access Management (IAM) service account that bosh-bootloader needs to interact with GCP:

1. If you installed the gcloud CLI for the first time, initialize it:
    <pre class="terminal">$ gcloud init</pre> 

1. Create the IAM service account for bosh-bootloader with the gcloud CLI:
    <pre class="terminal">$ gcloud iam service-accounts create bbl-user --display-name "BBL"</pre>
1. Navigate to the GCP Console and under **Project info**, retrieve your **Project ID**. 
1. Create keys for the service account, replacing `YOUR-PROJECT-ID` with the project ID you retrieved in the previous step:
    <pre class="terminal">$ gcloud iam service-accounts keys create \
    --iam-account='bbl-user<span>@</span>YOUR-PROJECT-ID.iam.gserviceaccount.com' \
    bbl-user.key.json</pre>
    This command outputs a `bbl-user.key.json` file. Store this file in a safe and secure place.
1. Add the Editor role to the service account:
    <pre class="terminal">$ gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
    --member='serviceAccount:bbl-user<span>@</span>YOUR-PROJECT-ID.iam.gserviceaccount.com' \
    --role='roles/editor'</pre>

## <a id="create-infra-bosh"></a> Step 3: Create the Infrastructure and the BOSH Director

Run the following command to create the required infrastructure and deploy a BOSH Director:

<pre class="terminal">
bbl up \
  --iaas gcp \
  --gcp-service-account-key PATH-TO/bbl-user.key.json \
  --gcp-region YOUR-GCP-REGION
</pre>

Replace the placeholders as follows:

* `PATH-TO` is the path to the `bbl-user.key.json` file, created in the previous section.
* `YOUR-GCP-REGION` is your GCP region, such as `us-central1`.

The `bbl up` command takes five to eight minutes to complete. When the process finishes, it outputs a state file, `bbl-state.json`, in the present working directory.

<p class="note"><strong>Note</strong>: The <code>bbl-state.json</code> file contains credentials and other metadata related to your BOSH Director and infrastructure. Back up this file and store it in a safe location, and never modify it manually.</p>

To extract information from the `bbl-state.json` state file, use bosh-bootloader instead of opening the file. For example, to obtain your BOSH Director address, run the following command:

<pre class="terminal">$ bbl director-address
https://YOUR-DIRECTOR-ADDRESS
</pre>

Run `bbl` to see the full list of values from the state file that you can print. You must always run `bbl` from the directory that contains `bbl-state.json`.

## <a id='create-lbs'></a> Step 4: Create Load Balancers

To create your load balancers, run the following command:
<pre class="terminal">
$ bbl create-lbs --type cf --cert YOUR-CERT.crt --key YOUR-KEY.key --domain YOUR-SYSTEM-DOMAIN
</pre>

Replace the placeholders as follows:

* `YOUR-CERT.crt` and `YOUR-KEY.key` are the path to your Certificate Authority (CA) certificate and key. This enables SSL/TLS termination at your load balancer.
* `YOUR-SYSTEM-DOMAIN` is the DNS domain name for your Cloud Foundry instance. Cloud Foundry uses this domain name when deploying apps. For example, if you select the name `cloud.example.com`, Cloud Foundry deploys each of your apps as `APP-NAME.cloud.example.com`.

For more information about the options for securing HTTP traffic into your Cloud Foundry (CF) deployment with SSL/TLS certificates, see the [Securing Traffic into Cloud Foundry](../../adminguide/securing-traffic.html) topic.

For test and development environments, you can also generate your own CA certificate and key with a tool such as [certstrap](https://github.com/square/certstrap).

## <a id='update-dns'></a> Step 5: Update DNS Records

The `create-lbs` command creates an NS record in Google's CloudDNS. You can view this record by navigating to the [GCP Console and selecting **Networking > Cloud DNS**.

The data associated with the record will have the following format:

```
ns-cloud-e1.googledomains.com.
ns-cloud-e2.googledomains.com.
...
```

From your domain registrar, delegate DNS authority for your hosted zone to the four CloudDNS name servers. To do this, replace your registrar's NS records for the domain with the NS record values listed in CloudDNS.

After a few minutes, your system domain should resolve to your GCP load balancer.

## <a id="connect-bosh-director"></a> Step 6: Connect to the BOSH Director

Perform the following steps to connect to the BOSH Director:

1. Save the Certificate Authority (CA) certificate to a file and set the path as an environment variable:
    <pre class="terminal">
    $ bbl director-ca-cert > bosh.crt
    $ export BOSH\_CA\_CERT=bosh.crt
    </pre>

1. Set your BOSH Director address as an environment variable:
    <pre class="terminal">
    $ export BOSH_ENVIRONMENT=$(bbl director-address)
    </pre>

1. Obtain your BOSH Director username and password:
    <pre class="terminal">
    $ bbl director-username
    YOUR-DIRECTOR-USERNAME
    $ bbl director-password
    YOUR-DIRECTOR-PASSWORD
    </pre>

1. Set your target and log in with the BOSH CLI:
    <pre class="terminal">
    $ bosh alias-env YOUR-TARGET-NAME
    $ bosh log-in
    Username: YOUR-DIRECTOR-USERNAME
    Password: <PASSWORD>
    </pre>
    Replace `YOUR-TARGET-NAME` with a target name to associate with the BOSH Director address, such as `my-bosh`. You use this target name to log in to your BOSH Director in the future.
    <br><br>
    Replace `YOUR-DIRECTOR-USERNAME` and `YOUR-DIRECTOR-PASSWORD` with the values you obtained from `bbl` in the previous step.

## <a id="destroy-environment"></a>Destroy the BOSH Resources ##

You can use <code>bbl destroy</code> to delete the BOSH Director infrastructure in your GCP environment. Use this command if `bbl up` does not complete successfully and you want to reset your environment, or if you want to destroy the resources created by bosh-bootloader for any other reason.

To destroy your BOSH resources, run the following command:
<pre class="terminal">$ bbl destroy</pre><commit_msg>Update GCP install docs for bbl v6 syntax.<commit_after>---
title: Deploying BOSH on GCP
owner: Release Integration
---

<strong><%= modified_date %></strong>

This topic describes how to use the [bosh-bootloader](https://github.com/cloudfoundry/bosh-bootloader)
command-line tool to set up an environment for Cloud Foundry on Google Cloud
Platform (GCP) and deploy a [BOSH Director](https://bosh.io/docs/bosh-components.html#director).

## <a id='overview'></a>Overview

After completing this topic, you will have the following:

1. A BOSH Director instance in the Availability Zone (AZ) of your choice

1. A set of randomly generated BOSH Director credentials

1. A generated key pair that allows you to SSH into the BOSH Director and any instances that BOSH deploys

1. A copy of the manifest you use to deploy the BOSH Director
    <p class="note"><strong>Note</strong>: A <a href="https://bosh.io/docs/deployment-manifest.html">manifest</a> is a YAML file that defines the components and properties of a BOSH deployment.</p>

1. A basic cloud config 
    <p class="note"><strong>Note</strong>: A <a href="https://bosh.io/docs/cloud-config.html">cloud config</a> is a YAML file that defines IaaS-specific configuration for BOSH.</p>

1. A set of load balancers
    <p class="note"><strong>Note</strong>: bosh-bootloader creates the load balancers, but you must still configure DNS to point your domains to the load balancers. See the <a href="../common/dns_prereqs.html">Setting Up DNS for Your Environment</a> topic for more information.</p>

## <a id='downloads'></a> Step 1: Download Dependencies

Perform the following steps to download the required dependencies for bosh-bootloader:

1. Download [Terraform](https://www.terraform.io/downloads.html) v0.9.1 or later. Unzip the file and move it to somewhere in your PATH:
    <pre class="terminal">
    $ tar xvf ~/Downloads/terraform*
    $ sudo mv ~/Downloads/terraform /usr/local/bin/terraform
    </pre>

1. Download the [BOSH CLI v2](https://bosh.io/docs/cli-v2.html#install). Make the binary executable and move it to somewhere in your PATH:
    <pre class="terminal">
    $ chmod +x ~/Downloads/bosh-cli-*
    $ sudo mv ~/Downloads/bosh-cli-* /usr/local/bin/bosh
    </pre>

1. Perform one of the following procedures to download and install bosh-bootloader:
    * On Mac OS X, use Homebrew:
        <pre class="terminal">$ brew install cloudfoundry/tap/bbl</pre>

    * Download the latest bosh-bootloader from [GitHub](https://github.com/cloudfoundry/bosh-bootloader/releases/latest). Make the binary executable and move it to somewhere in your PATH:
        <pre class="terminal">
        $ chmod +x ~/Downloads/bbl-*
        $ sudo mv ~/Downloads/bbl-* /usr/local/bin/bbl
        </pre>

1. Download and install the [gcloud CLI](https://cloud.google.com/sdk/downloads).

## <a id='create-iam'></a> Step 2: Create an IAM Service Account

Perform the following steps to create the Identity and Access Management (IAM) service account that bosh-bootloader needs to interact with GCP:

1. If you installed the gcloud CLI for the first time, initialize it:
    <pre class="terminal">
    $ gcloud init
    </pre>

1. Create the IAM service account for bosh-bootloader with the gcloud CLI:
    <pre class="terminal">
    $ gcloud iam service-accounts create bbl-user --display-name "BBL"
    </pre>

1. Navigate to the GCP Console and under **Project info**, retrieve your **Project ID**.

1. Create keys for the service account, replacing `YOUR-PROJECT-ID` with the project ID you retrieved in the previous step:
    <pre class="terminal">
    $ gcloud iam service-accounts keys create \
    --iam-account='bbl-user<span>@</span>YOUR-PROJECT-ID.iam.gserviceaccount.com' \
    bbl-user.key.json
    </pre>

    This command outputs a `bbl-user.key.json` file. Store this file in a safe and secure place.

1. Add the Editor role to the service account:
    <pre class="terminal">
    $ gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
    --member='serviceAccount:bbl-user<span>@</span>YOUR-PROJECT-ID.iam.gserviceaccount.com' \
    --role='roles/editor'
    </pre>

## <a id="create-infra-bosh"></a> Step 3: Create Infrastructure, Bastion, BOSH Director, and Load Balancers

Run the following command to create the required infrastructure,
deploy a bastion, deploy a BOSH director and create load balancers
for Cloud Foundry:

    <pre class="terminal">
    $ bbl plan \
      --iaas gcp \
      --gcp-service-account-key PATH-TO/bbl-user.key.json \
      --gcp-region YOUR-GCP-REGION \
      --lb-type cf \
      --lb-cert YOUR-CERT.crt \
      --lb-key YOUR-KEY.key \
      --lb-domain YOUR-SYSTEM-DOMAIN

    $ bbl up
    </pre>

Replace the placeholders as follows:

* `PATH-TO` is the path to the `bbl-user.key.json` file, created in the previous section.
* `YOUR-GCP-REGION` is your GCP region, such as `us-central1`.
* `YOUR-CERT.crt` and `YOUR-KEY.key` are the path to your Certificate Authority (CA) certificate and key. This enables SSL/TLS termination at your load balancer.
* `YOUR-SYSTEM-DOMAIN` is the DNS domain name for your Cloud Foundry instance. Cloud Foundry uses this domain name when deploying apps. For example, if you select the name `cloud.example.com`, Cloud Foundry deploys each of your apps as `APP-NAME.cloud.example.com`.

The `bbl up` command takes five to eight minutes to complete.
When the process finishes, it outputs a state file, `bbl-state.json`, in the present working directory.

<p class="note"><strong>Note</strong>: The <code>bbl-state.json</code> file
contains credentials and other metadata related to your BOSH Director and
infrastructure. Back up this file and store it in a safe location, and never
modify it manually.</p>

To extract information from the `bbl-state.json` state file, use bosh-bootloader
instead of opening the file. For example, to obtain your BOSH Director address,
run the following command:

    <pre class="terminal">
    $ bbl director-address
    https://YOUR-DIRECTOR-ADDRESS
    </pre>

Run `bbl` to see the full list of values from the state file that you can print.
You must always run `bbl` from the directory that contains `bbl-state.json`.

For test and development environments, you can also generate your own CA certificate and key with a tool such as [certstrap](https://github.com/square/certstrap).

## <a id='update-dns'></a> Step 5: Update DNS Records

The `create-lbs` command creates an NS record in Google's CloudDNS. You can view
this record by navigating to the [GCP Console and selecting **Networking > Cloud DNS**.

The data associated with the record will have the following format:

```
ns-cloud-e1.googledomains.com.
ns-cloud-e2.googledomains.com.
...
```

From your domain registrar, delegate DNS authority for your hosted zone to the
four CloudDNS name servers. To do this, replace your registrar's NS records for
the domain with the NS record values listed in CloudDNS.

After a few minutes, your system domain should resolve to your GCP load balancer.

## <a id="connect-bosh-director"></a> Step 6: Connect to the BOSH Director

Run the following:

    <pre class="terminal">
    $ eval "$(bbl print-env)
    </pre>

## <a id="destroy-environment"></a>Destroy the BOSH Resources ##

To delete load balancers:

    <pre class="terminal">
    $ bbl plan
    $ bbl up
    </pre>


To delete the infrastructure, bastion, director, and load balancers:

    <pre class="terminal">
    $ bbl destroy
    </pre>


If `bbl up` does not complete successfully and you want to reset your environment,
or if you want to destroy the resources created by bosh-bootloader for any other
reason, run the above command.
{'fraction_non_alphanumeric': 0.10399951740363154, 'fraction_numerical': 0.0037401218555830366, 'mean_word_length': 3.8332361516034985, 'pattern_counts': {'":': 0, '<': 158, '<?xml version=': 0, '>': 161, 'https://': 20, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1336037', 'n_tokens_mistral': 5107, 'n_tokens_neox': 4918, 'n_words': 2017}