# Setup

## What Will You Do

This is Part 1 of the self-paced quick start exercise. In this part, you will use the Infra Admin persona to setup and configure the needed resources to use Environment Manager.

---

## Step 1: Import Template

In this step, you will use the Loader Utility to import the Environment Manager templates needed for this environment. This process will also setup a System Sync pipeline which will be used to create environment templates.

- Follow the instructions [here](https://docs.rafay.co/env_manager/loader/) to use the loader
- When using the loader utility, be sure to use a private repository which will create System Sync pipeline
- When using the loader utility, be sure to uncomment the following template **\- ../terraform/rafay-aws-resources** in the templates section of the values.yaml file

---

## Step 2: Configure Environment Contexts

In this step, you will configure an environment context in the controller with your AWS account details. These account details will be used by Environment Manager to interact with your cloud account.

- Log into the controller and select your project
- Navigate to **Environments -> Contexts**
- Click on the context named **rafay-aws-<PROJECT NAME>**
- Select **Environment Variables**
- Populate the values of the variables with the access key and secret for your AWS account
- Ensure that you select the sensitive checkbox for both fields
- Click **Save**

Important

The Rafay agent automatically writes back the environment variables to Git. The resources (esp. secrets) you identify as **sensitive** will be automatically encrypted using a secret sealer before being synced to your Git repo.

---

## Step 3: Configure Resource Template Variables

In this step, you will update the resource template for the AWS security group resource. You will be updating specific variables in the resource template to use expressions. The expressions will use the output of the VPC resource template when used together in the same environment template.

- Navigate to **Environments -> Resource Templates**
- Find and click on the template named **rafay-aws-security-group**
- Click **New Version**
- Enter **v2** for the version name
- Navigate to the **Input Variables** section

- Update the variable **vpc_id** with value **$(resource["rafay-aws-vpc"].output.vpc_id.value)$**

- Set the value type to **Expressions**

- Update the variable `ingress_with_cidr_blocks` with the below values

```
[\
    {\
        "from_port": 1433,\
        "to_port": 1433,\
        "protocol": "tcp",\
        "description": "SqlServer access from within VPC",\
        "cidr_blocks": "$(resource[\"rafay-aws-vpc\"].output.vpc_cidr_block.value)$"\
    }\
]
```

- Set the value type to **JSON**
- Click **Save as Active Version**

---

## Step 4: Create VPC and Security Group Environment Template

In this step, you will use the System Sync pipeline to create an environment template for the the VPC and security group environment.

- Navigate to your Git repository
- Navigate to **<REPO NAME>/rafay-resources/projects/<PROJECT NAME>/environmenttemplates**
- Create a new file named **vpc-and-security-group.yaml**
- Copy the below contents into the file being sure to update the project name and any variable values to match your specific environment

```
apiVersion: eaas.envmgmt.io/v1
kind: EnvironmentTemplate
metadata:
  name: vpc-and-security-group
  project: UPDATE_ME
  description: Create a VPC and Security Group in AWS
  displayName: AWS VPC and Security Group
spec:
  iconURL: https://cdn2.iconfinder.com/data/icons/amazon-aws-stencils/100/Non-Service_Specific_copy_Virtual_Private_CLoud_-512.png
  readme: "## Introduction\n\nUsers can use this template\n  to create a VPC and Security Group in AWS \n\n---\n\n##\n  What does this do behind the scenes? \n\nThis template will perform the following\n  in a sequence: \n\n1. Create a new VPC in AWS using the name of the environment \n2. Create a Security Group within the VPC using the name of the environment\n \n\n---\n\n## Defaults and Overrides \nUnless specified, the\n  new VPC will be created with the default settings for the AWS region and subnets.  The subnets include private, public and database subnet groups\n  Users have the option to override the defaults with alternative options. See the input variables section below for complete details. "
  resources:
  - kind: resourcetemplate
    name: rafay-aws-vpc
    resourceOptions:
      version: v1
    type: dynamic
  - dependsOn:
    - name: rafay-aws-vpc
    kind: resourcetemplate
    name: rafay-aws-security-group
    resourceOptions:
      version: v2
    type: dynamic
  variables:
  - name: region
    options:
      override:
        type: allowed
      required: true
    value: us-west-2
    valueType: text
  - name: azs
    options:
      override:
        type: allowed
      required: true
    value: '[
