This example automates the creation of a GitHub repository, infrastructure provisioning with Terraform, and generates a PR for setting up an RDS instance.
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:
Save the Workflow example YAML file below:
name:"Dev Onboarding: Environment Setup"tag:dev-onboarding-env-setupdescription:"This workflow automates the creation of a GitHub repository, infrastructure\ \ provisioning with Terraform, and generates a PR for setting up an RDS instance."isDraft:falsefilter:type:GLOBALrunResponseTemplate:nullfailedRunResponseTemplate:nullrestrictActionCompletionToRunnerUser:falseactions:- name:Transform User Infoslug:transform-user-infoschema:expression:.context.initiatedBy.name + "-repo"type:JQoutgoingActions: - scaffold-hello-orgisRootAction:true- name:Scaffold Hello Org Reposlug:scaffold-hello-orgschema:scaffolderTemplateId:st363f187d3e1a826ecreateNewRepository:truecreateService:nullinputOverrides: - inputKey:repo_nameoutputVariable:actions.transform-user-info.outputs.resulteditable:falsetype:VALUEtype:SCAFFOLDERoutgoingActions: - trigger-workflowisRootAction:false- name:Terraform Infrastructure Provisioningslug:trigger-workflowschema:inputs:ref:mainrepo:cortex-workshops/terraforminputs:"{\"user\": \"{{context.initiatedBy.name}}\"}"workflow_id:.github/workflows/main.yamlintegrationAlias:cortexactionIdentifier:github.createWorkflowDispatchEventtype:ADVANCED_HTTP_REQUESToutgoingActions: - scaffold-rds-terraformisRootAction:false- name:Open PR with RDS terraformslug:scaffold-rds-terraformschema:scaffolderTemplateId:st363f198d56473124createNewRepository:falsecreateService:nullinputOverrides: - inputKey:publisherRepoFullNameoutputVariable:actions.scaffold-hello-org.outputs.response.gitURLeditable:falsetype:VALUEtype:SCAFFOLDERoutgoingActions: - notify-developerisRootAction:false- name:Notify Developerslug:notify-developerschema:channel:all-es-testingmessage:"Hi, {{context.initiatedBy.name}}! Your new test environment is ready\ \ to go!"type:SLACKoutgoingActions: []isRootAction:falserunRestrictionPolicies: []iconTag:Keyboardvariables: []
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:
Click + in the center of the page. In the block library modal, choose Data transformation.
In the block configuration side panel, enter a name and unique slug for this block.
In this example, we use the name Transform user info and the slug transform-user-info.
Add a jq expression to take the initiator's name and add -repo to it:
.context.initiatedBy.name + "-repo"
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.
Click + in the center of the page. In the block library modal, select the Scaffolder block.
In the side panel, enter a name and unique slug for the block.
In this example, we use the name Scaffold Hello Org Repo and the slug scaffold-hello-org.
Under Scaffolder template, select your template. In this example, we use Hello Org Template.
Select the option to Create a new repo.
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:
This overrides the Repo Name field with the output of the "Transform user info" block earlier in the Workflow.
At the bottom of the side panel, click Save.
Trigger GitHub workflow
This block triggers Terraform infrastructure in GitHub.
Click + in the center of the page. In the block library modal, select the GitHub > Trigger workflow block.
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.
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}}"}
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.
Click + in the center of the page. In the block library modal, select the Scaffolder block.
In the side panel, enter a name and unique slug for the block.
In this example, we use the name Open PR with RDS terraform and the slug scaffold-rds-terraform.
Under Scaffolder template, select your template. In this example, we use Terraform RDS Template.
Select the option to Open a pull request.
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: