# Set up networking

All applications in an environment share a common network (VPC).

The default VPC for your environment set up by this guide is: `{Environment}`

## Step 1: Add and configure the `networking` package

```bash title="repo-iac/environments/dev/"
ok pkg add networking
```

Update `package-config.yml` with your preferences.

## Step 2: Install the package

```bash title="repo-iac/environments/dev/networking/"
ok pkg install
```

## Step 3: Configure CIDR range

You must claim a range and document this in the [Google doc](https://docs.google.com/spreadsheets/d/1Ly-gVkakvZ2ZtcS3aDb0E2ZYOMEFUb6fE3Ma7mVsVKI/edit?gid=0#gid=0) created for this purpose.
Each VPC must have a unique CIDR range within the Origo AWS organization.

Once you've claimed a range, edit `config_override.tf` and set the CIDR range:

```hcl title="repo-iac/environments/dev/networking/config_override.tf"
vpc_cidr_block = "{value-chosen}"
```

<!-- prettier-ignore-start -->
!!! note "Release CIDR block"
    The CIDR block must be released (removed from the Google doc) once the VPC is no longer in use.
<!-- prettier-ignore-end -->

## Step 4: Apply in this order (required)

**Order matters:** Apply **data first**, then **networking**.
The **networking stack depends on resources** created by the data stack.

### 1) Apply the data stack (required first)

Creates S3 buckets and other data resources.

```bash title="repo-iac/environments/dev/networking-data/"
terraform init
terraform apply
```

### 2) Apply the networking stack (run second)

Creates the VPC and networking resources.

```bash title="repo-iac/environments/dev/networking/"
terraform init
terraform apply
```

## Step 5: Verify

=== "AWS CLI"

    Run the following command:

    ```bash
    aws ec2 describe-vpcs | jq '.Vpcs[].Tags[]? | select(.Key == "Name") | .Value'
    ```

    The output list should contain the name of the VPC you just created.

=== "AWS console"

    Login to the AWS console and navigate to **VPC**. Select **Your VPCs** in the left-hand menu.

    The list should contain the name of the VPC you just created.

---

--8<-- "includes/commit.md"

One step of the Networking setup remains: the load balancer.

## Next step

Set up [load balancing](set-up-load-balancing.md).
