The landing zone deployment process consists of
[stages](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-stages.md.txt). During each stage, you
must add certain variables to the `terraform.tfvars` file. After you complete a
stage, Terraform writes a `tfvar.auto.tfvars.json` file to the [Cloud Storage](https://docs.cloud.google.com/storage/docs.md.txt)
bucket that's created in the initial stage. Subsequent stages use
the Google Cloud CLI to copy the files and a provider file that impersonates a
stage-specific service account into the new stage folder.

Depending on the number of tenants, deploying a new environment
takes approximately one hour.

## Prerequisites

Complete the following tasks before deploying Stellar Engine.

### Set up Google Cloud

Complete the following steps to set up Google Cloud:

1. Select a Google Cloud organization. If you create a new organization,
   sign in to the [Google Admin console](https://admin.google.com) at least
   once.

2. Configure multiple administrators to implement separation of duties. In a
   testing environment, one user might have administrator roles for all
   resources. However, in a production environment, you require multiple
   administrators. For more information, see [Set up your organization
   resource](https://docs.cloud.google.com/resource-manager/docs/creating-managing-organization#setting-up).

   > [!NOTE]
   > **Note:** If you have access issues, grant the roles to yourself on the organization node or have your administrator grant them for you. You might need to reload the page in your browser or sign out and sign back in to the Google Cloud console to apply the new permissions.

3. Enable [2-step verification](https://docs.cloud.google.com/docs/authentication/mfa-requirement.md.txt) for all
   privileged accounts.

4. [Disable Cloud Shell](https://docs.cloud.google.com/shell/docs/resetting-cloud-shell.md.txt).
   Cloud Shell isn't supported for IL4 or IL5 environments and must be
   disabled by a Google Workspace administrator.

5. If you don't have a project, [create a bootstrap
   project](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects).


   [Create a project](https://console.cloud.google.com/projectcreate)

   <br />

6. Complete the following tasks in the bootstrap project:

   1. Enable billing. For instructions, see [Verify the billing status of your
      projects](https://docs.cloud.google.com/billing/docs/how-to/verify-billing-enabled).


   2.


      Enable the Cloud Monitoring API, if it is not already enabled.


      **Roles required to enable APIs**


      To enable APIs, you need the `serviceusage.services.enable` permission. If you
      created the project, then you likely already have this permission through the
      Owner role (`roles/owner`). Otherwise, you can get this permission through the
      Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
      [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

      [Enable the API](https://console.cloud.google.com/apis/enableflow?apiid=monitoring.googleapis.com)
7. Verify that your user account is a [Super
   Admin](https://admin.google.com/ac/roles).

8. If your organization doesn't have a data classification scheme, create one.

### Assign roles

Assign the following [Identity and Access Management](https://docs.cloud.google.com/iam/docs.md.txt) roles to the user account
that's deploying Stellar Engine.

1.

   Make sure that you have the following role or roles on the organization:

   Access Transparency Admin, Assured Workloads Administrator, Billing Account Administrator, Logging Admin, Organization Administrator, Organization Policy Admin, Organization Role Administrator, Owner, Project Creator, Service Account Admin, Service Account Token Creator, Tag Admin

   #### Check for the roles

   1.
      In the Google Cloud console, go to the **IAM** page.

      [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=organizationId)
   2. Select the organization.
   3.
      In the **Principal** column, find all rows that identify you or a group that
      you're included in. To learn which groups you're included in, contact your
      administrator.

   4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.

   #### Grant the roles

   1.
      In the Google Cloud console, go to the **IAM** page.

      [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=organizationId)
   2. Select the organization.
   3. Click **Grant access**.
   4.
      In the **New principals** field, enter your user identifier.

      This is typically the email address for a Google Account.

   5. Click **Select a role**, then search for the role.
   6. To grant additional roles, click **Add
      another role** and add each additional role.
   7. Click **Save**.

<br />

If you are starting with a new organization, you can run the following
script that's located in the
[fast/stages-aw/0-bootstrap](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/0-bootstrap)
folder to apply the roles:

```bash
./setIAM.sh EMAIL_ADDRESS ORGANIZATION_ID
```

Replace the following:

- `EMAIL_ADDRESS`: the email address of your user account.
- `ORGANIZATION_ID`: your organization ID.

This script adds all roles except for Billing Account Administrator and Super
Admin.

> [!CAUTION]
> **Caution:** When you run this script, you lose all current permissions for your user account except for Super Admin.

### Add groups and configure services

1. In the **Stage 2** section of **Google Cloud Setup** , add the following
   groups, as described in [Users and
   groups](https://docs.cloud.google.com/docs/enterprise/advanced-production#checklist-section-2):

   - Required FAST stage groups:

   - `gcp-billing-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-devops@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-organization-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-vpc-network-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   > [!NOTE]
   > **Note:** Google Cloud Setup recommends `gcp-network-admins` for the network group. Rename `gcp-network-admins` to `gcp-vpc-network-admins` or override the group name in the `groups` variable during the `0-bootstrap` stage.

   - `gcp-security-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - Optional application groups:

   - `gcp-developers@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-logging-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-logging-viewers@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>

   - `gcp-monitoring-admins@`<var class="edit" scope="DOMAIN" translate="no">DOMAIN</var>


   [Go to Stage 2](https://console.cloud.google.com/cloud-setup/overview)

   <br />

   Replace `DOMAIN` with your fully qualified domain
   name (FQDN).

   If prompted, skip the identity provider step.

   > [!NOTE]
   > **Note:** You don't have to complete subsequent steps, but make sure you finish Step 2.

   You can also manually create a [group](https://docs.cloud.google.com/iam/docs/groups-in-cloud-console.md.txt) if
   it isn't in the setup guide.


2.


   Enable the Assured Workloads, BigQuery, Cloud Billing, Cloud Logging, Cloud KMS, IAM, Pub/Sub, Resource Manager, Service Account Credentials, Service Usage, Organization Policy Service APIs, if any are not already enabled.


   **Roles required to enable APIs**


   To enable APIs, you need the `serviceusage.services.enable` permission. If you
   created the project, then you likely already have this permission through the
   Owner role (`roles/owner`). Otherwise, you can get this permission through the
   Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
   [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

   [Enable the APIs](https://console.cloud.google.com/apis/enableflow?apiid=assuredworkloads.googleapis.com,bigquery.googleapis.com,cloudbilling.googleapis.com,logging.googleapis.com,cloudkms.googleapis.com,iam.googleapis.com,pubsub.googleapis.com,cloudresourcemanager.googleapis.com,iamcredentials.googleapis.com,serviceusage.googleapis.com,orgpolicy.googleapis.com)
3. You can also use the [`fast/stages-aw/0-bootstrap/enableServices.sh`](https://github.com/google/stellar-engine/blob/main/fast/stages-aw/0-bootstrap/enableServices.sh) script to enable the services.

> [!NOTE]
> **Note:** If you encounter issues with the script, you can run the following deprecated command on macOS and other Unix variants:
>
> ```bash
> echo "iam cloudkms pubsub serviceusage cloudresourcemanager bigquery assuredworkloads cloudbilling logging iamcredentials orgpolicy" | xargs -n1 -I {} gcloud services enable "{}.googleapis.com"
> ```

4. [Enable Access
   Transparency](https://docs.cloud.google.com/assured-workloads/access-transparency/docs/enable).

5. If your quota is less than 13 projects, go to [Google Cloud Platform/API
   Project: Request Billing Quota
   Increase](https://support.google.com/code/contact/billing_quota_increase) to
   request 13 projects. For more information, see [View and manage
   quotas](https://docs.cloud.google.com/docs/quotas/view-manage).

### Configure your local environment

Complete the following steps in a Linux command shell, a macOS terminal, or
Windows Subsystem for Linux 2 (WSL 2) to configure your local environment:

1. Clone the [Stellar Engine GitHub
   repository](https://github.com/google/stellar-engine/).
2. Install [Google Cloud SDK](https://cloud.google.com/sdk/docs/install).
3. Update your local [Terraform](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli) to match the `required_version` constraint in the `modules/*/versions.tf` files. Terraform 1.10.2 or later is supported.
4. Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) to run the `stellar` command-line interface (CLI) from the `cli/` directory.
5. Install the [jq binary](https://jqlang.github.io/jq/download/).
6. Authenticate and set the bootstrap project as the active project:

   ```bash
   gcloud auth login
   gcloud config set project BOOTSTRAP_PROJECT_ID
   gcloud auth application-default login
   ```

   Replace `BOOTSTRAP_PROJECT_ID` with the ID of the
   project that you created in [Set up Google Cloud](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough.md.txt#gcp-setup).

### Modify modules

In most circumstances, you can use the repository without changes. If you need
to modify a module, copy the entire module and use the naming convention
`&lt;module-se&gt;` to avoid merge conflicts when periodic updates are pulled in
from the Cloud foundation fabric repository.

## Run Stage 0: Bootstrap

Stage 0 aligns the existing parts of the network with the Terraform state. Stage
0 creates the initial IaC bootstrap service accounts and projects. Stage 0
designed to transition from whatever project the user initially has into a new
core project and migrate the Terraform state.

1. Change directory into
   [`fast/stages-aw/0-bootstrap`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/0-bootstrap).

2. Copy the `terraform.tfvars.sample` file:

   ```bash
   cp terraform.tfvars.sample terraform.tfvars
   ```
3. Copy the `providers.tf.tmp` file to the `0-bootstrap-providers.tf` file:

   ```bash
   cp providers.tf.tmp 0-bootstrap-providers.tf
   ```
4. Update the variables in the `fast/stages-aw/0-bootstrap/terraform.tfvars`
   file:

   ```terraform
   billing_account = {
   id = "BILLING_ACCOUNT_ID"
   }
   regions = {
   primary = "REGION"
   }
   organization = {
   domain = "DOMAIN"
   id = "ORGANIZATION_ID"
   customer_id = "CUSTOMER_ID"
   }
   outputs_location = "~/fast-config"
   prefix = "PREFIX"
   log_sinks = {
   audit-logs = {
   filter = "logName:\"/logs/cloudaudit.googleapis.com%2Factivity\" OR logName:\"/logs/cloudaudit.googleapis.com%2Fsystem_event\" OR protoPayload.metadata.@type=\"type.googleapis.com/google.cloud.audit.TransparencyLog\""
   type = "logging"
   }
   vpc-sc = {
   filter = "protoPayload.metadata.@type=\"type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata\""
   type = "logging"
   }
   workspace-audit-logs = {
   filter = "logName:\"/logs/cloudaudit.googleapis.com%2Fdata_access\" and protoPayload.serviceName:\"login.googleapis.com\""
   type = "logging"
   }
   empty-audit-logs = {
   filter = ""
   type = "logging"
   }
   }
   org_policies_config = {
     constraints = {
       allowed_policy_member_domains = []
       allowed_vpc_peering_producers = ["under:organizations/433637338589"]
       }
     }
   kms_protection_level = "KMS_PROTECTION_LEVEL"
   fast_features = {
   envs = true
   }
   assured_workloads = {
   regime = "COMPLIANCE_REGIME"
   location = "LOCATION"
   }
   bootstrap_project = "BOOTSTRAP_PROJECT_ID"
   alert_email = "ALERT_EMAIL"
   ```

   Replace the following:
   - `BILLING_ACCOUNT_ID`: the billing account to use for the
     deployment of the environments. To find the billing account information, see
     the Google Cloud console.


     [Go to Billing](https://console.cloud.google.com/billing)

     <br />

   - `REGION`: the primary region to deploy
     resources into. The default is `us-east4` for IL5 and FedRAMP.

     To add a secondary region to deploy resources into, add
     `secondary = "SECONDARY_REGION"`, where
     `SECONDARY_REGION` is the name of the secondary
     region.
   - `DOMAIN`: the FQDN. To view the FQDN, run
     `gcloud organizations list`.

   - `ORGANIZATION_ID`: the organization ID for the
     Google Cloud organization. To view the organization ID, run `gcloud
     organizations list`.

   - `CUSTOMER_ID`: the Google Workspace
     Directory customer ID. To view the ID, run `gcloud organizations list`.

   - `PREFIX`: the prefix to append to the names for
     projects and resources that are deployed. The project name must be
     globally unique and the prefix must contain a maximum of seven characters.
     A 409 error occurs if the project name isn't unique.

   - `KMS_PROTECTION_LEVEL`: the Cloud Key Management Service
     protection level for all stages. Use `SOFTWARE` for `FEDRAMP_MODERATE` and
     `HSM` for `FEDRAMP_HIGH` and `IL5`. If omitted, Stage 0 selects a
     regime-aware default (`SOFTWARE` for `FEDRAMP_MODERATE` and `HSM` for all
     other regimes).

   - `COMPLIANCE_REGIME`: the [compliance
     regime](https://assuredworkloads.googleapis.com/$discovery/rest?version=v1)
     for this environment, one of `IL4`, `IL5`, `FEDRAMP_MODERATE`,
     `FEDRAMP_HIGH`, or `COMPLIANCE_REGIME_UNSPECIFIED`. If you don't want to
     use Assured Workloads, set this value to
     `COMPLIANCE_REGIME_UNSPECIFIED`. Stage 0 also tailors custom organization
     policies by regime. For example, it enforces `compute.requireOsLogin` for
     `FEDRAMP_MODERATE`, `FEDRAMP_HIGH`, and `COMPLIANCE_REGIME_UNSPECIFIED`
     but omits it for `IL4` and `IL5`, where
     Assured Workloads manages OS Login directly.

   - `LOCATION`: the US region to deploy resources
     into. Dual regions such as `NAM9` or continents aren't supported.

   - `BOOTSTRAP_PROJECT_ID`: the ID of the project
     that you created in [Set up Google Cloud](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough.md.txt#gcp-setup).

   - `ALERT_EMAIL`: the email address to send
     logging alert notifications to.

5. Optional: Update the following variables in the
   `fast/stages-aw/0-bootstrap/terraform.tfvars` file:

   - `allowed_policy_member_domains`: To grant IAM roles to
     principals from other trusted domains (such as partner agencies or
     contractors), add their Google Workspace or Cloud Identity
     customer IDs to the list. For more information, see [Restrict identities
     with domain-restricted sharing](https://docs.cloud.google.com/organization-policy/restrict-domains).

   - `allowed_vpc_peering_producers`: To allow VPC Network Peering with
     additional organizations, folders, or projects, add the IDs for these
     resources to the list. The
     [`constraints/compute.restrictVpcPeering`](https://docs.cloud.google.com/organization-policy/reference/org-policy-constraints.md.txt#constraints/compute.restrictVpcPeering)
     organization policy constraint uses this list to define which resources can
     peer with your organization's VPC networks. By default, the list includes the Google
     service producer organization (`under:organizations/433637338589`), which
     is required for [private services
     access](https://docs.cloud.google.com/vpc/docs/private-services-access#org-policies) and private
     Google Kubernetes Engine (GKE) clusters.

   - `deploy_org_resources`: For existing deployments or folder-scoped
     deployments without organization-level IAM permissions,
     update the fields in this variable to disable organization-level resource
     creation and scope audit logs and IAM bindings to the
     Assured Workloads folder. You can disable one or more
     resources, as required by your deployment. For example:

     ```terraform
     deploy_org_resources = {
       audit_config = false
       custom_roles = false
       iam          = false
       logging_settings = false
       logging_sinks    = false
       org_policies     = false
       workforce_identity_pool = false
     }
     ```
   - `log_sinks`: To send logs to Pub/Sub for SIEM ingestion instead of
     a Cloud Logging bucket, set the log sink type to `pubsub`. Make sure
     that your [Pub/Sub subscriber](https://docs.cloud.google.com/pubsub/docs/subscriber.md.txt) is
     reading and storing messages from the topic so that logs aren't lost after
     the default seven-day [message retention
     duration](https://docs.cloud.google.com/pubsub/docs/subscription-properties#message-retention-duration).

   - `billing_account`: If you can't modify IAM bindings on a
     shared billing account, set `no_iam = true`. Import any existing projects
     (using the `project_deletion_policies` variable) and
     Assured Workloads workloads, as described in the
     [`cli/README.md`](https://github.com/google/stellar-engine/blob/main/cli/README.md)
     file.
     For more information, see [Configure billing when using external billing
     accounts](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#configure-billing).

6. From the root directory of the repository, verify the prerequisites before
   initializing Terraform:

   ```bash
   uv run --project cli stellar preflight \
     --org ORGANIZATION_ID \
     --billing-account BILLING_ACCOUNT_ID \
     --project BOOTSTRAP_PROJECT_ID \
     --prefix PREFIX \
     --regime COMPLIANCE_REGIME \
     --region REGION
   ```

   Fix all failed checks before proceeding.

   The `stellar` CLI includes other commands, such as `stellar init`, `stellar
   imports scan`, and `stellar render`. You can use these commands to record
   deployment answers in the `answers.yaml` file, generate organization policy
   `import` blocks, and render isolated Stage 0 and Stage 1 workspaces. For more
   information, see the
   [`cli/README.md`](https://github.com/google/stellar-engine/blob/main/cli/README.md)
   file.
7. Run `terraform init`.

8. Run `terraform apply`:

   ```bash
   terraform apply -var bootstrap_user=$(gcloud config list --format
    'value(core.account)')
   ```
9. Type `yes` when prompted.

10. Switch to your new project:

    ```bash
    gcloud config set project PREFIX-prod-iac-core-0
    ```
11. Copy the new local Terraform providers file:

    ```bash
    gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/providers/0-bootstrap-providers.tf ./
    ```
12. Migrate the state from local to remote:

    ```bash
    terraform init --migrate-state
    ```
13. Type `yes` when prompted.

14. Run `./import.sh`.

15. Run `terraform apply` one more time. Type `yes` when prompted.

## Run Stage 1: Resource management

Stage 1 creates the different folders, projects, and service accounts at the
organization level that are used for subsequent stages. To create the
environment, you must update the `terraform.tfvars` file in
`fast/stages-aw/1-resman` to include a `tenants` variable. Each tenant (for
example, a specific federal agency or internal development group) gets its own
dedicated, isolated boundary to run its workloads. Each tenant inherits the
centralized security controls, networking perimeter, policy guardrails, and
audit log sinks that are created in Stage 0 and Stage 2.

1. If you are using an external billing account, see [Configure billing when
   using external billing accounts](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#configure-billing).

2. Change directory into
   [`fast/stages-aw/1-resman`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/1-resman).

3. Copy the `terraform.tfvars.sample` file:

   ```bash
   cp terraform.tfvars.sample terraform.tfvars
   ```
4. Update `terraform.tfvars` as follows:

   ```terraform
   tenants = {
   ten-1 = {
     admin_principal = "group:gcp-devops@DOMAIN"
     descriptive_name = "TENANT_ONE_NAME"
     locations = {
       gcs = "REGION"
       kms = "REGION"
       }
     },
   ten-2 = {
     admin_principal = "group:gcp-devops@DOMAIN"
     descriptive_name = "TENANT_TWO_NAME"
     locations = {
       gcs = "REGION"
       kms = "REGION"
       }
     }
   }
   fast_features = {
   envs = true
   }
   envs_folders = {
   Prod = {
     admin = "gcp-organization-admins@DOMAIN"
   },
   Int = {
     admin = "gcp-organization-admins@DOMAIN"
   },
   Test = {
     admin = "gcp-organization-admins@DOMAIN"
   }
   }
   ```

   Replace the following:
   - `DOMAIN`: the primary FQDN. To view the FQDN,
     run `gcloud organizations list`.

   - `TENANT_ONE_NAME`: the name for the first tenant
     project that's deployed. Use a maximum of six characters.

   - `REGION`: the primary region to deploy resources
     into. The default is `us-east4` for IL5 and FedRAMP.

   - `TENANT_TWO_NAME`: the name for the second tenant
     project that's deployed. Use a maximum of six characters.

   Add as many tenant definitions as you require.
5. Optional: To override the organization-level policy constraints on tenant
   projects, create one or more YAML files that define the organization
   policy constraints in the `fast/stages-aw/1-resman/data/org-policies/`
   directory. To use a different directory, set `factories_config.org_policies`
   in the `fast/stages-aw/1-resman/terraform.tfvars` file.

   For example, to allow an additional custom VM image project on tenant
   projects while keeping the parent organization's allowed image projects,
   create a YAML file that includes the following:

   ```yaml
   compute.trustedImageProjects:
     inherit_from_parent: true
     rules:
       - allow:
           values:
             - projects/IMAGE_PROJECT_ID
   ```

   Replace `IMAGE_PROJECT_ID` with the project ID that
   hosts your trusted VM images.
6. Copy the `tfvars` files from Cloud Storage:

   ```bash
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/providers/1-resman-providers.tf ./ &&
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-globals.auto.tfvars.json ./ &&
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-bootstrap.auto.tfvars.json ./
   ```
7. Run `terraform init`.

8. Run `terraform apply`. Type `yes` when prompted.

## Run Stage 2: Network creation

Stage 2 includes two networking options: one for [FedRAMP High or
FedRAMP Moderate](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#stage2-fedramp) and one for [IL4 or IL5](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough.md.txt#stage2-il5).

### Configure networking for FedRAMP High or Moderate

1. If you are using an external billing account, see [Configure billing when
   using external billing accounts](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#configure-billing).

2. Change directory into
   [`fast/stages-aw/2-networking-a-fedramp`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/2-networking-a-fedramp).

3. Copy the provider and global tfvars files from the Cloud Storage buckets:

   ```bash
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/providers/2-networking-providers.tf ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-globals.auto.tfvars.json ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-bootstrap.auto.tfvars.json ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/1-resman.auto.tfvars.json ./
   ```
4. Copy the `terraform.tfvars.sample` file:

   ```bash
   cp terraform.tfvars.sample terraform.tfvars
   ```
5. In the `terraform.tfvars` file, update the custom subnets, proxy subnets,
   firewall rules, named CIDRs, and DNS response policy rules.

6. Run `terraform init`.

7. Run `terraform apply`. Type `yes` when prompted.

### Configure networking for IL4 or IL5

This step deploys a pair of Palo Alto VM-Series Next-Generation Firewalls
(NGFWs) into the network account. The NGFWs use the Bring Your Own License
(BYOL) deployment image and require you to use the Palo Alto console to upload a
VM code and register them. For more instructions, see the README in the
[`2-networking-b-il5-ngfw`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/2-networking-b-il5-ngfw)
stage folder.

1. If you are using an external billing account, see [Configure billing when
   using external billing accounts](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#configure-billing).

2. Change directory into
   [`fast/stages-aw/2-networking-b-il5-ngfw`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/2-networking-b-il5-ngfw).

3. Copy the provider and global tfvars files from the Cloud Storage buckets:

   ```bash
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/providers/2-networking-providers.tf ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-globals.auto.tfvars.json ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-bootstrap.auto.tfvars.json ./ && \
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/1-resman.auto.tfvars.json ./
   ```
4. Copy the `terraform.tfvars.sample` file:

   ```bash
   cp terraform.tfvars.sample terraform.tfvars
   ```
5. In the `terraform.tfvars` file, update the custom subnets (including mgmt),
   proxy subnets, firewall rules, named CIDRs, and DNS response policy rules.

6. Run `terraform init`.

7. Run `terraform apply`. Type `yes` when prompted.

   If you receive an error about a service account or Cloud KMS not
   existing, in the console, click **Settings** in the
   `PREFIX-net-vdss-host` storage
   account. The service account is generated.

## Run Stage 3: Security and audit account configuration

Stage 3 configures the security and audit projects. The security project
(`prod-sec-core-0`) contains Cloud KMS and can contain
Secret Manager. In IL5, CMEK is enabled by default for
Compute Engine, GKE, Cloud Storage, and
Cloud SQL. The following organization policy constraints are enforced:

- `gcp.restrictNonCmekServices`:
  - `denied_values: "compute.googleapis.com"`
  - `denied_values: "container.googleapis.com"`
  - `denied_values: "storage.googleapis.com"`
  - `denied_values: "sqladmin.googleapis.com"`
- `gcp.restrictCmekCryptoKeyProjects`: `gcp.restrictCmekCryptoKeyProjects` includes a list of projects that can use CMEK.

In the `prod-sec-core-0` project, the following items are configured:

- Cloud KMS restricted admins are granted the restricted Admin role so that they can grant decrypt permissions to other services.
- Cloud KMS key rings in different locations are provisioned. The key ring locations must match the service locations. For example, a multi-regional key ring cannot be used in a single region's storage bucket.

The audit project (`audit-logs-0`) is a centralized location for
organization-level logs. These logs are divided into the following categories:

- `audit-logs`: Administrator activities, system events, and Access Transparency logs
- `vpc-sc`: VPC Service Controls logs
- `workspace-audit-logs`: Google Workspace logs for sign-ins and data access
- `empty-audit-logs`: all other logs

This project can include CMEK-encrypted Logging buckets, or it can
include Pub/Sub topics that route the logs for ingestion into a
SIEM. The default option is Logging buckets with default retention
periods of 365 days. To change the retention period, use the
`logging_bucket_retention` variable that's defined in the Stage 0
`terraform.tfvars` file.

Security administrators are responsible for the security project and auditors
are responsible for the audit project.

1. If you are using an external billing account, see [Configure billing when
   using external billing accounts](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/deployment-walkthrough#configure-billing).

2. Change directory into
   [`fast/stages-aw/3-security`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/3-security).

3. Copy the configuration files from the Cloud Storage buckets:

   ```bash
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/providers/3-security-providers.tf ./ &&
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-globals.auto.tfvars.json ./ &&
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/0-bootstrap.auto.tfvars.json ./ &&
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/1-resman.auto.tfvars.json ./
   ```
4. Run `terraform init`.

5. Run `terraform apply`. Type `yes` when prompted.

   If you encounter an issue with service accounts, rerun `terraform apply`.
6. Run `./sa_lockdown.sh` to disable the service accounts that you used during
   deployment.

   > [!NOTE]
   > **Note:** You might be unable to deploy certain blueprints unless the service accounts are enabled. If you are deploying additional services or blueprints into the Stellar Engine environment, don't run this script until your deployments are complete.

## Configure billing when using external billing accounts

If you are using an external billing account, you can add the Billing Account
Administrator role to required service accounts or use a billing override.

Complete one of the following:

- Add the Billing Account Administrator role to the following service accounts:

  - `PREFIX-prod-resman-0@PREFIX-prod-iac-core-0.iam.gserviceaccount.com`:
    This service account is created in Stage 0.

  - `PREFIX-prod-resman-net-0@PREFIX-prod-iac-core-0.iam.gserviceaccount.com`:
    This service account is created in Stage 1.

  - `PREFIX-security-0@PREFIX-prod-iac-core-0.iam.gserviceaccount.com`:
    This service account is created in Stage 2.

  Replace `PREFIX` with the prefix for your
  deployment.

  To add the role to these service accounts, complete [Access the Permissions
  panel for a Cloud Billing
  account](https://docs.cloud.google.com/billing/docs/how-to/grant-access-to-billing#access-permissions-panel)
  and [Update roles and principals in the Permissions
  panel](https://docs.cloud.google.com/billing/docs/how-to/grant-access-to-billing#update-roles-principals).
- If you can't grant billing permissions to the stage service accounts, use a
  billing override to run project creation or billing links using your personal
  credentials. Define the `billing_override` variable in the following
  `terraform.tfvars` files:

  - `fast/stages-aw/1-resman/terraform.tfvars`
  - `fast/stages-aw/2-networking-a-fedramp/terraform.tfvars` or `fast/stages-aw/2-networking-b-il5-ngfw/terraform.tfvars`
  - `fast/stages-aw/3-security/terraform.tfvars`

  ```terraform
  billing_override = {
    project         = "QUOTA_PROJECT_ID"
    billing_project = "QUOTA_PROJECT_ID"
  }
  ```

  Replace `QUOTA_PROJECT_ID` with the project ID for your quota
  project.

## Modify tenant projects

Perform the following steps when adding or removing tenant projects for an
existing Stellar Engine deployment.

1. Authenticate and set the active project:

   ```bash
   gcloud auth login
   gcloud config set project PREFIX-prod-iac-core-0
   gcloud auth application-default login
   ```

   Replace `PREFIX` with the prefix that you
   configured for your deployment.
2. Enable the service accounts for the stages:

   1. Change directory into
      [`fast/stages-aw/3-security`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/3-security).

   2. Run `./sa_lockdown.sh --enable`.

3. Apply Stage 1:

   1. Change directory into
      [`fast/stages-aw/1-resman`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/1-resman).

   2. Update the information in `terraform.tfvars` to your new requirements.

   3. Run `terraform init`.

   4. Run `terraform apply`. Type `yes` when prompted.

4. Apply Stage 2:

   1. Change directory into one of the following network folders:

      - [`fast/stages-aw/2-networking-a-fedramp`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/2-networking-a-fedramp)
      - [`fast/stages-aw/2-networking-b-il5-ngfw`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/2-networking-b-il5-ngfw)
   2. Copy the `1-resman` tfvars file from the Cloud Storage bucket:

   ```bash
   gcloud storage cp gs://PREFIX-prod-iac-core-outputs-0/tfvars/1-resman.auto.tfvars.json ./
   ```
   1. Run `terraform init`.

   2. Run `terraform apply`. Type `yes` when prompted.

5. Disable the service accounts for the stages:

   1. Change directory into
      [`fast/stages-aw/3-security`](https://github.com/google/stellar-engine/tree/main/fast/stages-aw/3-security).

   2. Run `./sa_lockdown.sh`.

## Troubleshooting

This section describes some common errors and resolutions.

### BigQuery isn't usable error in stage 1

If you get an error that `bigquery.googleapis.com` isn't usable in
Assured Workloads, complete the following:

1. In the console, go to the Assured Workloads page.


   [Assured Workloads](https://console.cloud.google.com/compliance/assuredworkloads)

   <br />

2. Select the `StellarEngine-PREFIX`
   folder and Networking folder, if applicable, where
   `PREFIX` is the prefix for your deployment.

3. Click **Review Available Updates**.

4. Go to **Allowed Services**.

5. Click **Allow services** to add the BigQuery APIs.

6. If prompted, click **Yes** to confirm your choice.

7. Wait about two minutes and then re-run `terraform apply`:

   ```bash
   terraform apply -var bootstrap_user=$(gcloud config list --format 'value(core.account)')
   ```
8. Type `yes` when prompted.

### Your bootstrap project loses access to your billing account

If your bootstrap project loses access to your billing account, re-enable billing for your bootstrap project.

[Enable billing](https://console.cloud.google.com/billing/projects)

### Cloud KMS key errors

If key errors occur during the build process, you might have to manually enable
the keys. For instructions, see [Enable a key
version](https://docs.cloud.google.com/kms/docs/enable-disable#enable).

If you receive these errors, wait about one minute and rerun `terraform apply`.

### Symbolic links not working on Windows computers

Windows shell environments (for example, PowerShell, Command Prompt, Git Bash,
or Cygwin) aren't supported because stage linking and deployment scripts rely on
POSIX path resolution and symbolic links. Complete the following:

1. On a Windows workstation, clone the repository inside a WSL 2 Linux file
   system (for example, `~/stellar-engine` rather than `/mnt/c/`) or a dev
   container.

2. Run all commands from that environment.

3. If symbolic links still fail during Stage 2, copy the `psc.tf` and
   `log-metric-alerts.tf` files into the stage directory manually.

### Cross-stage IAM impersonation 403 Forbidden errors

Each deployment stage uses a dedicated automation service account that's
configured in its generated `*-providers.tf` file. If you encounter `403
Forbidden` or `iam.serviceAccounts.getAccessToken` errors when transitioning
between stages, complete the following:

1. Clear stale shell impersonation variables by running one of the following:

   - `unset GOOGLE_IMPERSONATE_SERVICE_ACCOUNT
     CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT`
   - `../../stage-links.sh OUTPUTS_LOCATION`

   Replace `OUTPUTS_LOCATION` with the outputs
   location directory path that you configured in Stage 0 (for example,
   `~/fast-config`).

   These commands ensure that Terraform uses the stage's `*-providers.tf`
   configuration.
2. If you disabled the deployment service accounts in Stage 3, in the
   `fast/stages-aw/3-security` directory, run
   `./sa_lockdown.sh --enable`.

3. Verify that your active `gcloud auth list` identity belongs to the
   `gcp-organization-admins` or `gcp-devops` group that has the Service Account
   Token Creator (`roles/iam.serviceAccountTokenCreator`) role on the target
   stage service account.

### Billing or quota issues

If you encounter billing or quota issues, verify that your quota project is set.
You can set it by running the following:

```bash
gcloud auth application-default set-quota-project PREFIX-prod-iac-core-0
```

Replace `PREFIX` with the prefix for your
deployment. Optionally, you can use another project.

### Organization policy constraint `compute.restrictVpcPeering` violated

Stage 0 configures the
[`constraints/compute.restrictVpcPeering`](https://docs.cloud.google.com/organization-policy/reference/org-policy-constraints.md.txt#constraints/compute.restrictVpcPeering)
organization policy constraint using your organization node
(`under:organizations/ORGANIZATION_ID`,
where `ORGANIZATION_ID` is your organization ID) and
the `org_policies_config.constraints.allowed_vpc_peering_producers` list in the
`fast/stages-aw/0-bootstrap/terraform.tfvars` file.

If you deploy services or blueprints that use [private services
access](https://docs.cloud.google.com/vpc/docs/private-services-access#org-policies) or private
GKE clusters with VPC Network Peering, complete the following:

1. Include the Google service producer organization (`under:organizations/433637338589`) in `org_policies_config.constraints.allowed_vpc_peering_producers`.
2. Rerun `terraform apply` in the `fast/stages-aw/0-bootstrap` directory.

## What's next

- Review the [Stellar Engine Security Best Practices
  Guide](https://github.com/google/stellar-engine/blob/main/docs/security-best-practices.md)
  and [Security
  Policy](https://github.com/google/stellar-engine/blob/main/SECURITY.md) for
  post-deployment hardening and vulnerability reporting guidance.

- For additional security configuration, see [Gemini security
  standards](https://docs.cloud.google.com/docs/security/compliance/stellar-engine/gemini-considerations).

- Integrate a SIEM solution such as
  [Google Security Operations](https://docs.cloud.google.com/chronicle/docs/secops/secops-overview.md.txt) to monitor
  the resources. Segment your SIEM in a separate Google Cloud project and
  on a separate VPC from where it is collecting data.