# Part 1: Create

This is Part 1 of a multi-part exercise that will focus on creating and sharing a blueprint across projects within an organization.

---

## What Will You Do

In part 1, you will:

- Create a new project in your organization
- Create a cluster blueprint
- Share the blueprint across projects
- Apply the blueprint to a cluster

---

## Step 1: Create Project

In this step, we will create a new project which will serve as a logically isolated "operating environment" (sub tenant). To learn more, see [Project](https://docs.rafay.co/security/tenancy/projects/).

**Note**  
Creating a project requires "[Org Admin](https://docs.rafay.co/security/rbac/roles/)" privileges.

We will create a project named "central". This project will be used to house the source blueprint we will create in an upcoming step. Then we will share this blueprint with another project.

- Create a new project called "central"

- Switch context to the "central" project by clicking on the project in the web console

You can create a project using RCTL. See [CLI Setup](https://docs.rafay.co/cli/config/) to install the RCTL CLI.

- Create a `project.yaml` file. The project name is "central" in the following example.

```yaml
apiVersion: system.k8smgmt.io/v3
kind: Project
metadata:
  description: getstarted_project
  name: central
spec:
  default: false
```

- Run `./rctl apply -f project.yaml` to create the project.
- Run `./rctl config set project central` to set the project.
- Run `./rctl config show` to see the current RCTL configuration. Make sure `central` appears for project.

While it is possible to create a project using Terraform, a key benefit of using Terraform is creating multiple things at once.

Go to [Step 2](https://docs.rafay.co/learn/quickstart/blueprint/blueprintlifecycle/create/#step-2-create-blueprint) to create a project and a blueprint.

---

## Step 2: Create Blueprint

In this step, we will create a custom blueprint based off the "minimal" blueprint.

- Navigate to the previously created "central" project in your Org
- Select Infrastructure -> Blueprints
- Click "New Blueprint"
- Enter a name for the blueprint
- Select "Custom Blueprint" for the Type
- Click "Save"

Next, create a blueprint version for this custom blueprint.

- Enter the "Version Name"
- Select the minimal blueprint as the base blueprint
- Click "Save Changes"

You can create a blueprint using RCTL.

- Create a `blueprint.yaml` file. Use the following example.

```yaml
apiVersion: infra.k8smgmt.io/v3
kind: Blueprint
metadata:
  name: test-blueprint
  project: central
```

- Run `./rctl apply -f blueprint.yaml --v3` to create the blueprint.
- Run `./rctl get blueprints --v3` to see a list of blueprints in the project.

You can create a project and a blueprint using Terraform. See [Install Terraform](https://developer.hashicorp.com/terraform/downloads) to install Terraform.

- Download the [Getting Started](https://github.com/RafaySystems/getstarted) package and extract it.
- Edit the `config.json` file. You can use a text editor. The path to the config file: /getstarted/terraform/blueprints/artifacts/credentials.
- Add your console API key, API secret, and Project ID to the `config.json` file.
- Open the Terminal and navigate to the **blueprints** folder in the **getstarted** package. The path: /getstarted/terraform/blueprints.
- Run `terraform init` to initialize the directory containing the Terraform configuration files, preparing the directory for use with Terraform.
- Run `terraform validate` to validate the configuration files in the directory, without accessing any remote services.
- Run `terraform apply` to create the project and blueprint. Enter `yes` when prompted.

---

## Step 3: Share Blueprint

In this step, we will share the previously created custom blueprint with the project where your cluster is located.

A shared blueprint cannot be deleted. Disable sharing first, then delete the blueprint.

- Navigate to the previously created "central" project in your Org
- Select Infrastructure -> Blueprints
- Click the "Manage Sharing" icon near the previously created blueprint

- Select "Specific Projects"
- Select the project where your cluster is located
- Click "Save"

You will now see the blueprint is shared across projects.

You can share a blueprint using RCTL. Enable sharing and include the project names to share the blueprint with.

- Update the `blueprint.yaml` file to match the example below.

```yaml
apiVersion: infra.k8smgmt.io/v3
kind: Blueprint
metadata:
  name: v1
  project: central
spec:
  base:
    name: default
    version: 1.21.0
  defaultAddons:
    enableIngress: true
    enableMonitoring: true
  sharing:
    enabled: true
    projects:
    - name: testproject
  type: custom
  version: "1"
```

- Run `./rctl apply -f blueprint.yaml --v3` to update the blueprint.
- Run `./rctl get blueprints --v3` to see a list of blueprints in the project.

You can share the blueprint using Terraform. Enable sharing and include the project names to share the blueprint with.

- Edit the `main.tf` file in the **blueprints** folder. The path to the file: /getstarted/terraform/blueprints/modules/blueprints.
- For `sharing.enabled`, change the setting to `true`.
- For `sharing.projects.name`, change the setting to a project with a cluster.
- Save the changes to the `main.tf` file.
- Open the Terminal and navigate to the **blueprints** folder in the **getstarted** package. The path: /getstarted/terraform/blueprints.
- Run `terraform apply` to update the blueprint. Enter `yes` when prompted.

---

## Step 4: Apply Blueprint

In this step, we will apply the blueprint to the existing cluster in the downstream project.

- Navigate to the project in your Org where the cluster is located.
- Select Infrastructure -> Clusters
- Click the gear icon on the cluster card
- Select "Update Blueprint"
- Select the previously created and shared blueprint
- Select the blueprint version
- Click "Save and Publish"

The blueprint will begin to be applied to the cluster.

The blueprint is now applied to the cluster.

When using RCTL, apply a blueprint using the update cluster command.

- Run `./rctl config set project <project_name>`. Change <project_name> to the name of the project with the cluster to apply the blueprint to.
- Run `./rctl update cluster <cluster_name> -b test-blueprint`. Change <cluster_name> to the name of the cluster to apply the blueprint to.

When using Terraform, apply a blueprint by updating the Terraform TFVARS file for the cluster. This exercise uses an existing cluster. See [Amazon EKS Cluster Lifecycle](https://docs.rafay.co/learn/quickstart/eks/clusterlifecycle/provision/) or [Azure AKS Cluster Lifecycle](https://docs.rafay.co/learn/quickstart/aks/clusterlifecycle/provision/) for exercises on creating a cluster.

- Edit the `terraform.tfvars` file for the cluster.
- Change the `blueprint_name` and `blueprint_version` to match the shared blueprint.
- Save the TFVARS file.
- In the Terminal, navigate to the folder containing the Terraform files for the cluster.
- Run `terraform apply` to apply the changes to the cluster. The shared blueprint is applied to the cluster.

---

## Recap

Congratulations! At this point, you have successfully created, shared and applied a custom cluster blueprint across projects.

---
