Dev onboarding: Environment setup

This example automates the creation of a GitHub repository, infrastructure provisioning with Terraform, and generates a PR for setting up an RDS instance.

Step 1: Register the Scaffolder templates

This Workflow uses two Scaffolder templates:

Follow the instructions to register the Scaffolder templates in Cortex.

Step 2: Start creating the Workflow

Follow the steps in the documentation to create a Workflow and configure its basic settings.

Step 3: Add blocks to the Workflow

The instructions on this page describe how to create this Workflow in the Cortex UI, but it is also possible to copy the Workflow YAML and add it to your workspace via the Cortex CLI. This allows you to quickly set up the example configuration then iterate on it for your own use case. Expand the tile below to learn more.

Workflow YAML instructions

To upload the Workflow example YAML into your workspace:

  1. Save the Workflow example YAML file below:

name: "Dev Onboarding: Environment Setup"
tag: dev-onboarding-env-setup
description: "This workflow automates the creation of a GitHub repository, infrastructure\
  \ provisioning with Terraform, and generates a PR for setting up an RDS instance."
isDraft: false
filter:
  type: GLOBAL
runResponseTemplate: null
failedRunResponseTemplate: null
restrictActionCompletionToRunnerUser: false
actions:
- name: Transform User Info
  slug: transform-user-info
  schema:
    expression: .context.initiatedBy.name + "-repo"
    type: JQ
  outgoingActions:
  - scaffold-hello-org
  isRootAction: true
- name: Scaffold Hello Org Repo
  slug: scaffold-hello-org
  schema:
    scaffolderTemplateId: st363f187d3e1a826e
    createNewRepository: true
    createService: null
    inputOverrides:
    - inputKey: repo_name
      outputVariable: actions.transform-user-info.outputs.result
      editable: false
      type: VALUE
    type: SCAFFOLDER
  outgoingActions:
  - trigger-workflow
  isRootAction: false
- name: Terraform Infrastructure Provisioning
  slug: trigger-workflow
  schema:
    inputs:
      ref: main
      repo: cortex-workshops/terraform
      inputs: "{\"user\": \"{{context.initiatedBy.name}}\"}"
      workflow_id: .github/workflows/main.yaml
    integrationAlias: cortex
    actionIdentifier: github.createWorkflowDispatchEvent
    type: ADVANCED_HTTP_REQUEST
  outgoingActions:
  - scaffold-rds-terraform
  isRootAction: false
- name: Open PR with RDS terraform
  slug: scaffold-rds-terraform
  schema:
    scaffolderTemplateId: st363f198d56473124
    createNewRepository: false
    createService: null
    inputOverrides:
    - inputKey: publisherRepoFullName
      outputVariable: actions.scaffold-hello-org.outputs.response.gitURL
      editable: false
      type: VALUE
    type: SCAFFOLDER
  outgoingActions:
  - notify-developer
  isRootAction: false
- name: Notify Developer
  slug: notify-developer
  schema:
    channel: all-es-testing
    message: "Hi, {{context.initiatedBy.name}}! Your new test environment is ready\
      \ to go!"
    type: SLACK
  outgoingActions: []
  isRootAction: false
runRestrictionPolicies: []
iconTag: Keyboard
variables: []
  1. Use the Cortex CLI to run this command, using the path to your Workflow YAML file: cortex workflows create -f <path-to-your-workflow.yaml>

Expand the tiles below to learn about each block in this Workflow and how to configure them in the Cortex UI:

Data transformation

Create a data transformation to take the Workflow initiator's name and append -repo to it:

  1. Click + in the center of the page. In the block library modal, choose Data transformation.

  2. In the block configuration side panel, enter a name and unique slug for this block.

    1. In this example, we use the name Transform user info and the slug transform-user-info.

  3. Add a jq expression to take the initiator's name and add -repo to it:

.context.initiatedBy.name + "-repo"
  1. At the bottom of the side panel, click Save.

Scaffolder

This block creates a new repository in your connected Git integration, using templating to apply the output of the previous block to the Scaffolder configuration.

  1. Click + in the center of the page. In the block library modal, select the Scaffolder block.

  2. In the side panel, enter a name and unique slug for the block.

    1. In this example, we use the name Scaffold Hello Org Repo and the slug scaffold-hello-org.

  3. Under Scaffolder template, select your template. In this example, we use Hello Org Template.

  4. Select the option to Create a new repo.

  5. Add override variables. The Variable dropdown pulls in all the variables that are able to be overridden in the Git provider and in the Scaffolder template. In this example, we apply the following override:

    • repo_name: actions.transform-user-info.outputs.result

      • This overrides the Repo Name field with the output of the "Transform user info" block earlier in the Workflow.

  6. At the bottom of the side panel, click Save.

Trigger GitHub workflow

This block triggers Terraform infrastructure in GitHub.

  1. Click + in the center of the page. In the block library modal, select the GitHub > Trigger workflow block.

  2. In the side panel, enter a name and unique slug for the block.

    • In this example, we use the name Terraform Infrastructure Provisioning and the slug trigger-workflow.

  3. Configure the block:

    • Repository: Enter your repository name.

    • Ref: Enter the Git reference to trigger the workflow on, e.g. main.

    • Workflow ID or file name: Enter the ID of the GitHub workflow or the file name of the workflow file.

      • In our example, we added .github/workflows/main.yaml.

    • Inputs: Optionally enter key-value pairs to pass to the workflow.

      • In our example, we added: {"user": "{{context.initiatedBy.name}}"}

  4. At the bottom of the side panel, click Save.

Scaffolder

This block opens a Pull Request to set up an RDS instance, using templating to apply the output of the previous block to the Scaffolder configuration.

  1. Click + in the center of the page. In the block library modal, select the Scaffolder block.

  2. In the side panel, enter a name and unique slug for the block.

    1. In this example, we use the name Open PR with RDS terraform and the slug scaffold-rds-terraform.

  3. Under Scaffolder template, select your template. In this example, we use Terraform RDS Template.

  4. Select the option to Open a pull request.

  5. Add override variables. The Variable dropdown pulls in all the variables that are able to be overridden in the Git provider and in the Scaffolder template. In this example, we apply the following override:

    • publisherRepoFullName: actions.scaffold-hello-org.outputs.response.gitURL

      • This overrides the Repo Name field with the output of the "Scaffold Hello Org Repo" block earlier in the Workflow.

  6. At the bottom of the side panel, click Save.

Slack message

In this step, we send a templated message via Slack informing the user that their test environment is ready.

  1. Click + in the center of the page. In the block library modal, select the Slack block.

  2. In the side panel, enter a name and unique slug for the block.

    • In this example we use the name Notify developer and the slug notify-developer.

  3. Select a Slack channel name.

  4. Enter text for the message that will be sent via Slack. In our example, we use the following:

Hi, {{context.initiatedBy.name}}! Your new test environment is ready to go!
  1. Save the block.

Step 4: Run the Workflow

When you run the Workflow, the following events happen:

  • The Data transformation block runs, which produces a repository name for the user based on your specified naming convention.

  • The Scaffolder runs, creating a new repository. The repo's name is based on the output of the previous block.

  • The GitHub "Trigger a workflow" block runs, which provisions Terraform infrastructure.

  • The second Scaffolder block runs, which opens a Pull Request to set up an RDS instance.

  • The Slack block runs, which sends a Slack message to the user to let them know that their test environment is ready.

Last updated

Was this helpful?