Create Basic Environment Template - Rafay Product Documentation

Environment Template

In this section, you will develop an "environment template" that will comprise the components described below. You will create these as declarative specs in Git and use Rafay's "Git-to-System" synchronization to load them into your Rafay Org. As you can see from the architecture diagram below, the entire experience is powered using an environment template that encapsulates and templatizes the custom application.

You will implement the steps described below

  1. You will first create and update the files locally on your machine.
  2. You will push them to a new branch in your Git repository.
  3. Once the files are loaded in the new branch, you will merge the new branch into the main branch. The main branch is actively monitored for changes by Rafay's GitOps pipeline.
  4. This will trigger the automated loading of the resources in your Rafay Org.

Step 1: Download Files

In this step, you will download and extract a ZIP archive which contains the specification files of the EM resources for this part of the guide along with the Infrastructure as Code files that are used by the Environment Manager resources.

You will use these files in the subsequent steps.


Step 2: View/Update Config Context

In this step, we will review and update the config context declarative spec file. In our example, this file stores two environment variables with one variable configured to contain sensitive data.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

apiVersion: eaas.envmgmt.io/v1
kind: ConfigContext
metadata:
  name: rafay-configcontext
  project: em-gs
spec:
  envs:
  - key: RCTL_API_KEY
    options:
      mask: true
      override:
        type: notallowed
      sensitive: true
    value: UPDATEVALUE
  - key: RCTL_API_SECRET
    options:
      mask: true
      override:
        type: notallowed
      sensitive: true
    value: UPDATEVALUE
  - key: RCTL_PROJECT
    options:
      override:
        type: notallowed
    value: defaultproject
  - key: RCTL_REST_ENDPOINT
    options:
      override:
        type: notallowed
    value: console.rafay.dev

Step 3: View/Update Resource Template

In this step, we will view and update the resource template. This resource template points to OpenTofu based IaC within the ZIP archive. The IaC files will be pushed to the Git repository, where the GitOps Agent will access and execute them when called.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

apiVersion: eaas.envmgmt.io/v1
kind: ResourceTemplate
metadata:
  name: em-rt-intermediate
  project: em-gs
spec:
  agents:
  - name: em-gs
  contexts:
  - name: rafay-configcontext
  provider: opentofu
  providerOptions:
    openTofu:
      backendType: system
  repositoryOptions:
    branch: main
    directoryPath: /terraform/intermediate/
    name: em-gs
  version: v1
  versionState: draft

Step 4: View/Update Environment Template

In this step, we will view and update the environment template declarative spec file. Note that this references the resource template from the prior step.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

apiVersion: eaas.envmgmt.io/v1
kind: EnvironmentTemplate
metadata:
  name: em-et-intermediate
  project: em-gs
spec:
  agents:
  - name: em-gs
  resources:
  - kind: resourcetemplate
    name: em-rt-intermediate
    resourceOptions:
      version: v1
    type: dynamic
  variables:
  - name: input_name
    options:
      displayMetadata:
        disabled: false
        section: ""
        sectionDescription: ""
        tooltip: ""
        weight: ""
      override:
        type: allowed
      required: true
    valueType: text
  - name: project
    options:
      displayMetadata:
        disabled: false
        section: ""
        sectionDescription: ""
        tooltip: ""
        weight: ""
      override:
        type: notallowed
    value: $(environment.project.name)$
    valueType: expression
  - name: cluster_name
    options:
      displayMetadata:
        disabled: false
        section: ""
        sectionDescription: ""
        tooltip: ""
        weight: ""
      override:
        type: allowed
      required: true
    valueType: text
  version: v1
  versionState: draft

Step 5: Create and Merge Git Branch

Now, you will create a new branch in your Git repository and copy the contents of the extracted ZIP archive to the branch. You will then merge this new branch into the main branch where Rafay's GitOps will detect the changes.

Once the changes are pushed into the new branch, we will now merge the changes into the main branch where Rafay GitOps will detect the changes and create the resources in your Rafay Org.


Step 6: Update Config Context

Now, you will go back into the Rafay Console and validate that the Config Context resource has been created. You will then update the sensitive variable value from the console. This will then encrypt the sensitive value and automatically write back to the Git repository. The values required to populate the config context can be found in the CLI Config file which can be downloaded from Home -> My Tools -> Download CLI Config.


Step 7: Validate Templates

In this step, you will validate that Rafay GitOps created the templates within Environment Manager.

You will see the newly created resource template.

You will see the newly created environment template.


Recap

In this part, you used Rafay GitOp's Git to System synchronization capability to create an environment template.