What you can manage
You can create all three script types with Terraform. Only request review scripts can be attached with Terraform. Delegation condition scripts and Paladin context scripts are still attached in the Opal UI. See What isn’t supported yet.
Requirements
- An Opal provider version that includes the
opal_scriptresource. See the provider changelog. - An API token that belongs to an admin. Creating, updating, and deleting scripts is admin-only.
Create a script
main.tf
The resource also exports
id, version, and updated_at.
The other two types are created the same way, without owner_id:
Attach a request review script to an approval stage
Reference the script’sid in opal_script_ids on a reviewer stage. This replaces the old workaround of looking up the script’s service user and listing it under service_user_ids.
opal_script_ids works the same way on opal_group and opal_configuration_template. It’s a set, so order doesn’t matter. Only REQUEST_REVIEW scripts can be reviewers; Opal rejects any other type.
Update a script
Changingscript saves a new version, just like selecting Save in the editor. version and updated_at update on the next refresh; they never cause drift on their own. Earlier versions stay in the editor’s version history.
Changing name renames the script and the service user behind it. Attachments follow the script, not its name.
A run uses the version that was current when it started. Runs that are paused with actions.pause or actions.poll finish on their original version.
Use an existing script
To reference a script that someone made in the editor without managing it in Terraform, use a data source:id, name, script (the latest version’s source), script_type, version, and updated_at. If more than one script has the name you look up, opal_script_from_name fails instead of picking one. Rename the scripts or look the script up by ID.
Import a script
To bring a script you made in the editor under Terraform management, import it by ID:scriptId query parameter), or with the opal_script_from_name data source.
After you manage a script with Terraform, make changes in code, not in the editor. Saving in the editor creates a new version that the next
terraform apply overwrites with the source in your repository. You can still use the editor to test runs and review run history.Delete a script
Removing anopal_script resource deletes the script and, for request review scripts, the service user Opal provisioned for it. Opal won’t delete a script that’s still in use:
- A request review script still attached to a resource or group. Remove it from
opal_script_idsin the same change, and Terraform detaches it before it deletes the script. - A delegation condition script used by any delegation, including delegations that have ended. Delete those delegations first.
What isn’t supported yet
- Attaching delegation condition scripts.
opal_delegationdoesn’t have a condition script field. Select the script under Condition script when you create the delegation in Opal. See Delegation conditions. - Attaching Paladin context scripts. Attach the script to a Paladin agent in Opal. See Paladin context.
- Secrets. Scripts read secrets with the
secretsmodule, but you create and manage secrets in Opal, not with Terraform. Don’t put secret values in script source.