Dynamic Target Settings
Overview
In some use cases, you will want to let your users input the name of the target they are requesting access to instead of declaring them all in your resources. Dynamic Target Settings allow you to do just that!
View layer setup
In this example, we will be using a GitHub Access flow. The goal is to request and grant access to the GitHub repository the user will type in the Slack request modal.
resource "sym_flow" "this" {
name = "github_access"
label = "Github Access"
template = "sym:template:approval:1.0.0"
implementation = "${path.module}/impl.py"
environment_id = var.sym_environment_id
vars = var.flow_vars
params = {
strategy_id = sym_strategy.this.id
prompt_fields_json = jsonencode(
[
{
name = "reason"
type = "string"
required = true
},
# This field will be bound to repo_name in the target resource next
{
name = "repo_name"
label = "Repository Name"
type = "string"
required = true
}
]
)
}
}
After applying this, the new "Repository Name" field will appear on the modal. In the next step, we will bind it to the actual GitHub target repo_name
settings!


Target configuration
In order to retrieve the input value from the new form field, we will use the field_bindings
attribute.
We can update our github_repo
target with the following:
resource "sym_target" "target" {
type = "github_repo"
# This is binding the repo_name form input to the repo_name field in the target
field_bindings = ["repo_name"]
# This is not needed anymore because provided by the field_bindings!
# name = "private-repo"
# label = "private-repo"
# settings = {
# repo_name = "private-repo"
#}
}
The fields_bindings
will allow Sym to interpret the following configuration:
resource "sym_target" "target" {
...
field_bindings = ["repo_name"]
}
So that it behaves like this:
resource "sym_target" "target" {
settings = {
repo_name = # whatever the user typed in the "repo_name" field in the slack modal
}
}
Results


Notes:
field_bindings
will take precedence over static fields- Make sure to make the modal field is marked as required if you are making a required setting dynamic.
- You are not limited to the
repo_name
. You can make any target settings dynamic!
Updated 7 months ago