Create Basic Environment Template - Rafay Product Documentation

Part 3

In this section, you will update the "environment template" to use a user supplied input variable. The input variable will be used by updated IaC files that will be pushed to your repository.

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.

Info

When you launch an instance of an environment based on this environment template it will execute the updated Infrastructure as Code (IaC) file. In our simple, illustrative example, we will print the user supplied input variable.


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 guide along with the Infrastructure as Code files that are used by the Environment Manager resources.

Download

You will use these files in the subsequent steps.


Step 2: Review IaC Files

In this step, we will review the IaC files to understand the updates being made. The variables.tf file has an additional variable called username added into the configuration. The main.tf file has an additional resource that will use the new variable and print it out.

variable "username" {
  description = "The name of the user to print"
  type        = string
  default     = "Tony Stark"
}
resource "null_resource" "username" {
  provisioner "local-exec" {
    command = <<EOF
###################################
#    Name of User: ${var.username}    #
###################################
EOF
  }
}

Step 3: 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. this will not trigger System Sync as this directory is outside of the directories System Sync monitors. However, these changes will be used by the IaC resource template, as this template is configured to use the IaC files in the terraform directory within the main branch of the repository.


Step 4: Update Environment Template

Now, you will go back into the Rafay Console and update the environment template with a user defined variable that will be linked to the newly created variable in the IaC files. This action will update the environment template specification file and automatically write back to the Git repository.


Step 5: Create Environment

In this step, we will create a new environment using the recently updated environment template. The environment will execute the IaC referred to by the resource template. In this step, we will validate the successful run by reviewing the log. As part of our IaC, we are printing the the input variable set during the environment run.

After a minute, the environment run will have completed.

You will see the output of the username variable value in the log output.


Recap

In this part, you updated the IaC files within the Git repository to use a new variable. You then updated the existing Environment Template to accept an input variable from the user. The input variable was then used by the IaC files.