Skip to content

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.

High Level Steps

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

  • Download the archive em-gs-part3.zip
  • Extract this archive on your local machine

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.

  • In your extracted archive from step 1, navigate to em-gs-part3/terraform/
  • Open the file named variables.tf in this directory
  • View the new variable added
variable "username" {
  description = "The name of the user to print"
  type        = string
  default     = "Tony Stark"
}
  • Open the file named main.tf in this directory
  • View the new resource added
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.

Git PR and Merge

  • Create a new branch in your Git repository
  • Click Add file -> Upload files
  • Add the folder named terraform that contains the files you viewed
  • Click Commit changes

Merge Branch

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.

  • Click Compare & pull request

Merge Branch

  • Click Create pull request

Merge Branch

  • Click Merge pull request

Merge Branch

  • Click Confirm merge

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.

  • In your project, navigate to Environments -> Environment Templates
  • CLick on the name of the environment template
  • Edit the template
  • Navigate to Input Variables
  • Click + Variable
  • Enter username for the name
  • Select Required to ensure the variable is set before deployment
  • Select Allowed to allow the variable value to be overridden at a higher level
  • Select Text for the Value Type
  • Click Save
  • Click No, Exit
  • Click Save as Draft

Config Context


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.

  • In your project, navigate to Environments -> Environments
  • Click Launch on the environment template card
  • Enter a name for the environment
  • Enter a value for the username variable
  • Click Save & Deploy

Environment

After a minute, the environment run will have completed.

  • Click Show near Activities (Recent Runs)
  • Expand group.em-rt.output

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

Environment


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.