> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aviatrix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy CoPilot Using Terraform

> If you are knowledgeable in deploying infrastructure-as-code using Terraform, you can deploy the Aviatrix CoPilot using a Terraform script rather than via the CSP marketplace.

If you are knowledgeable in deploying infrastructure-as-code using Terraform,
you can deploy the Aviatrix CoPilot using a Terraform script rather than via the
CSP marketplace.

For **AWS**, Terraform deployment is available through the
[Launch Aviatrix](https://launch.aviatrix.com) setup assistant.

## Launch CoPilot Instance Using Terraform

This section provides a summary of steps for launching a CoPilot single instance
(simple deployment) using Terraform.

<Check>
  This section only provides a summary of steps. Please refer to the
  documentation for the Aviatrix Terraform Module for CoPilot on GitHub here:
  [https://github.com/AviatrixSystems/terraform-modules-copilot](https://github.com/AviatrixSystems/terraform-modules-copilot) for the most
  current and detailed instructions.
</Check>

A CoPilot launched using Terraform is typically based on the latest CoPilot base
image version. You can verify with your Aviatrix representative the CoPilot base
image version being launched and record it for your records.

### Summary of steps for a CoPilot instance launch via Terraform

1. If you haven't already done so, subscribe to a CoPilot offer in the CSP
   marketplace. See <a href={"/docs/enterprise/" + "10.1" +
   "/guides/controlplane/copilot-planning-deployment#subscribe-copilot-offer"}>Subscribe
   to the Aviatrix CoPilot Offer in the Marketplace</a>.

   You only need to subscribe, review the subscription pricing information, and
   accept the terms and conditions in the marketplace before proceeding to the
   next step. You do not move on to the configuration steps in the marketplace.
   Note that to use the latest CoPilot features, you must also subscribe to the

   <a href={"/docs/enterprise/" + "10.1" + "/guides/controlplane/aviatrix-licensing"}>Aviatrix license</a>
   .

2. Verify your CSP account credentials and make sure you know which CSP region
   in which to launch CoPilot.

3. Go to the Aviatrix repository GitHub -
   AviatrixSystems/terraform-modules-copilot
   ([https://github.com/AviatrixSystems/terraform-modules-copilot](https://github.com/AviatrixSystems/terraform-modules-copilot)) to access the
   sample code in the *README* file for the applicable CSP. The *README* file
   contains the usage for the CoPilot instance launch.

4. In the folder where you put your Terraform scripts based on the sample code,
   create a *.tf* file to provide your CSP account credentials (for example,
   provider block below). You can name the *.tf* file whatever you want.

   <Check>
     Ensure your CSP account credentials are always in a secure location.
   </Check>

5. The following is an example of the format to enter your CSP account
   credentials. You can refer to your CSP Terraform Registry to verify the
   latest information that is required.

   Example of the format to enter your CSP account credentials :

   AZURE

   ```asciidoc theme={null}
   provider "azurerm" {
   features {}

   subscription_id = ""
   client_id    = ""
   client_secret  = ""
   tenant_id    = ""
   }
   ```

   GCP

   ```
   provider "google" {
   project = ""
   region = ""
   zone  = ""
   }
   ```

   OCI

   ```
   provider "oci" {
   tenancy_ocid   = ""
   user_ocid    = ""
   fingerprint   = ""
   private_key_path = ""
   region      = ""
   }
   ```

   AWS

   ```
   provider "aws" {
   region   = ""
   access_key = ""
   secret_key = ""
   }
   ```

   Refer to the Terraform Registry for the latest information.

6. Ensure that you set the variable for the region in which to launch the
   instance in the provider block.

7. Specify at least 1 data disk (volume) for Terraform to attach to your
   CoPilot instance for data storage.

   For information about CoPilot storage, see

   <a href={"/docs/enterprise/" + "10.1" + "/guides/controlplane/disk-management"}>CoPilot Disk (Volume) Management</a>
   .

   The following is sample code for building a single CoPilot instance. The
   variable default\_data\_volume\_name is required to create the data volume :

   ```
   module "copilot_build_aws" {
     source = "github.com/AviatrixSystems/terraform-modules-copilot.git//copilot_build_aws"

     allowed_cidrs = {
       "tcp_cidrs" = {
         protocol = "tcp"
         port = "443"
         cidrs = ["1.2.3.4/32"]
       }
       "udp_cidrs_1" = {
         protocol = "udp"
         port = "5000"
         cidrs = ["0.0.0.0/0"]
       }
       "udp_cidrs_2" = {
         protocol = "udp"
         port = "31283"
         cidrs = ["0.0.0.0/0"]
       }
     }

     keypair = "copilot_kp"

     default_data_volume_name = "/dev/sdf"
   }
   ```

8. Run terraform (terraform apply).

   The CoPilot instance is launched in the CSP as defined by the script's
   source field. If you do not specify an availability zone (using the variable
   `availability_zone`), an AZ that supports the instance type will be used.
   The AZ that is used will be listed in the output `ec2-info`.

   The instance launched is typically based on the latest CoPilot base image
   version. You can verify with your Aviatrix representative the CoPilot base
   image version being launched and record it for your records.

9. Wait to receive a success image message.

10. Launch the CoPilot application in your web browser:

    https: //copilot\_static\_ip\_address/

    where copilot\_static\_ip\_address is the static IP address

    of your newly deployed CoPilot software instance/virtual machine.

11. Perform the initial setup of CoPilot.

    See <a href={"/docs/enterprise/" + "10.1" +
    "/guides/controlplane/initial-setup"}>Initial Setup of CoPilot</a>.

12. Verify connectivity with your controller. See <a href={"/docs/enterprise/" +
    "10.1" +
    "/guides/controlplane/copilot-deployment-verification"}>Verify the CoPilot
    Deployment and the Connectivity with Controller</a>
