import blocks with terraform plan -generate-config-out. Set up the provider first: see Terraform Provider.
What you need
- Terraform 1.5 or later (OpenTofu 1.6 or later)
- Runlayer provider 1.14.1 or later. Earlier versions plan changes right after an import: a replace for a catalog server whose
catalog_entry_nameis left out, server settings reset to their defaults, andrunlayer_agentowner_idset to null. - A user API key, set up as in Terraform Provider
Adopt resources
1
Find the IDs
Each import needs the object’s import ID. For most resources it is the object’s ID; the import ID table lists the others.List servers and policies with the API:One call returns at most 500 servers or 100 policies. If a call returns that many, fetch the next page with
skip, for example ?skip=500&limit=500, until a page comes back short.2
Write import blocks
Add one To adopt every server at once, write the blocks from the API listing:Two servers whose names differ only in punctuation or case get the same address; rename one before you plan. With more than 500 servers, run it once per page and append (
import block per object, in a file such as import.tf. Do not write the resource blocks: Terraform generates them in the next step.>>) the output.Config generation does not work with
for_each in import blocks. Write one block per object, as above.3
Generate the configuration
resource block for it to generated.tf, which must not exist yet. The plan should end with:4
Review the generated configuration
Treat
generated.tf as a starting point:- Set every secret from a variable. Terraform cannot write secret values, so it writes
null # sensitiveinstead. A secret left asnullis cleared on apply. Onrunlayer_serverthis coverstransport_config.headers,transport_config.envand placeholder defaults. - Remove settings you do not want to manage. On
runlayer_serverand most other resources, a setting left out of the configuration keeps the value stored in Runlayer, so removing a line does not change the object. - Replace hard-coded IDs with references to other resources or data sources, such as
runlayer_group. - Move the blocks into the files and modules you want.
5
Plan until there are no changes
-/+): applying it deletes the live object and creates a new one.6
Apply
No changes. You can now delete import.tf; import blocks for objects already in state do nothing.Things to know
disable_auto_authis not stored, so it cannot be read back, and generated configuration leaves it out. Leaving it out keeps the server’sauth_type. Adddisable_auto_auth = trueonly if later applies must keepauth_typeas written; the first apply after adding it shows a one-line update.- Policy scope wildcards. When a policy’s
scope.toolsorscope.resourcesis all (*), generated configuration leaves it out, and that block imports and plans clean. To create a new policy from such a block, settoolsandresourcesexplicitly. - Resources without import.
runlayer_team_memberandrunlayer_team_group_bindingadopt an existing membership or binding when you apply them. Singletons such asrunlayer_organizationwrite their settings on apply, so declare them with the values you want. See Importing existing resources. - Users, groups and roles are not resources; read them with the
runlayer_user,runlayer_groupandrunlayer_roledata sources, or write their IDs to a tfvars file withuvx runlayer terraform export. See How the CLI can help. - Server secrets that Runlayer never returns, such as
manual_oauth_client_secretandbroker_vendor_client_secret, are absent after import and from generated configuration. Leaving them out plans no change.