Creating workspaces and importing your Terraform
Use a Schematics to manage your IBM Cloud Schematics resources using Terraform. Workspace settings define the Terraform engine hosted in a Git repository to be used, along with any input variables to customize the template.
IBM Cloud Schematics deprecates older version of Terraform. For more information, see Deprecating older version of Terraform process in IBM Cloud Schematics.
IBM Cloud Schematics deprecates creation of workspace using the IBM Cloud Provider Plug-in for Terraform v1.2, v1.3 template from 2nd week of April 2024.
Before you begin
- Create a Terraform configuration, and store the configuration in a
GitHub
,GitLab
, orBitbucket
repository. You can also upload a tape archive file (.tar
) from your local workstation to provide your template to IBM Cloud Schematics. For more information, see theibmcloud schematics workspace upload
command and see the upload atar
file to your workspace API. - Make sure that you have the permissions to create a workspace.
Ensure the location
and the url
endpoint are pointing to the same region when you create or update the Schematics workspaces and actions. For more information about location and endpoint, see Where is your information stored?
Creating a workspace using the UI
- Log in to IBM Cloud console.
- Click the Menu icon > Platform Automation > Schematics > Terraform > Create workspace.
- In Specify Template section:
-
GitHub, GitLab, or
Bitbucket
repository URL -<provide your Terraform Git repository URL
. -
Personal access token -
<leave it blank>
. You can click theOpen reference picker
to select a your Secret Manager key reference. For more information, see creating a Secret Manager instance. -
Terraform Version -
terraform_v1.4
. You need to select Terraform version 1.4 or greater version. For example, if your Terraform templates are created by using Terraform v1.4, select theTerraform version
parameter as terraform_v1.4. You can selectTerraform_v1.5
to use Terraform version 1.5,terraform_v1.4
to use Terraform version 1.4. When you specifyterraform_v1.5
means that users can have Terraformv1.5.0
,v1.5.1
, orv1.5.7
, so on. Schematics supportsTerraform_v1.x
and also plans to make releases available after30 to 45 days
of HashiCorp Configuration Language (HCL) release.Schematics supports the current release of
Terraform v1.4
, throughTerraform_v1.6
. The Terraform must use the version constraint, such as>
or>=
or~>
for therequired_version
of Terraform, to automatically pick the current version.terraform { required_version = "~> 1.1" }
-
Click
Next
.
-
- In Workspace details section. Enter a name for your
workspace name
. The name can be up to 128 characters long and can include alphanumeric characters, spaces, dashes, and underscores.- Workspace name as
schematics-agent-service
. - Tags as
my-tags
. Optional: Enter tags for your workspace. You can use the tags later to find your workspace faster. - Resource group as
default
or other resource group for this workspace. - Location as
North America
or other region for this workspace. Decide where you want to create your workspace? The location determines where your Schematics jobs run?, and where your workspace data is stored? You can choose between a location, such as North America, or a metro city, such as Frankfurt or London. If you select a location, Schematics determines the location based on availability. If you select a metro city, your workspace is created in this location. For more information about where your data is stored, see Where is your information stored? The location that you choose is independent from the region or regions where you want to provision your IBM Cloud resources. The console does not support all available locations. To create the workspace in a different location, use the CLI or API instead. - Optional, enter a descriptive name for your workspace.
- Click
Next
.
- Workspace name as
- Click
Create
. Your workspace is created with a Draft state and the workspace Settings page opens.
- In Specify Template section:
Importing your Terraform template
If you want to upload a tape archive file (.tar
) instead of importing your workspace to a Git repository, you must use the ibmcloud schematics workspace upload
command and see the upload a tar file to your workspace API.
-
On the workspace Settings page, enter the edit icon to edit your
Repository URL
. The link can point to themaster
branch, any other branch, or a subdirectory.- Example for
master
branch:https://github.com/myorg/myrepo
- Example for other branches:
https://github.com/myorg/myrepo/tree/mybranch
- Example for subdirectory:
https://github.com/mnorg/myrepo/tree/mybranch/mysubdirectory
- Example for
-
If you want to use a private Git repository, enter your personal access token. The personal access token is used to authenticate with your Git repository to access your Terraform template. You can click the
Open reference picker
to select a your Secret Manager key reference. For more information, see Creating a personal access token for the command-line and Creating a Secret Manager instance. If you want to clone from the Git repository see the allowed and blocked file extensions for cloning. -
Select the
Terraform version
that your Terraform configuration files are written in. -
Click the checkbox
I understand the changes that could happen if I edit this URL and I agree to these happening
option. -
Click Save. IBM Cloud Schematics automatically downloads the Terraform configuration files from your repository, scans them for syntax errors, and retrieves all input variables that you declared in your configuration files. When all configuration files are downloaded successfully and no syntax errors are found, the workspace state changes to Inactive.
After your Terraform configuration files are scanned, you can view the results on the workspace Activity page. The total number of files that were scanned in the source repository is displayed as
scanned
. The total number of files that are vulnerable, such as unsupported file extensions, is displayed asdiscarded
. Click Jobs to find the details of the files that were scanned and discarded. For more information about viewing logs, see Reviewing the Schematics job details. -
Review the default input variable values for your Terraform template. To change an input variable value, click Edit from the Workspace actions menu. Depending on the data type that your variable uses, you must enter the value in a specific format. see the following table to find example values for each supported data type.
Input variables and its sample values Type Example number
4.56 string
example value bool
false map(string)
{key1 = "value1", key2 = "value2"} set(string)
["hello", "he"] map(number)
{internal = 8080, external = 2020} list(string)
["us-south", "eu-gb"] list
["value", 30] list(list(string))
:[{internal = 8300 external = 8300 protocol = "tcp"
},{internal = 8301 external = 8301 protocol ="ldp"
} ] : list(object({internal = number external = number protocol = string})) : [{internal = 8300 external = 8300 protocol ="tcp"
} {internal = 8301 external = 8301 protocol ="ldp"
}]
Using Terraform templates in IBM Cloud
You can Manage IBM Cloud resources with Schematics to start creating, updating, or deleting IBM Cloud resources with Terraform.
Creating a workspace using the CLI
-
Create a JSON file on your local workstation and add your workspace configuration. For more configuration options when creating the workspace, see the
ibmcloud schematics workspace new
command.To create a workspace with Agent, refer to ibmcloud schematics workspace new with Agent command.
{ "name": "<workspace_name>", "type": [ "<terraform_version>" ], "location": "<location>", "description": "<workspace_description>", "tags": [], "template_repo": { "url": "<github_source_repo_url>" "branch": "master" }, "template_data": [ { "folder": ".", "type": "<terraform_version>", "variablestore": [ { "name": "<variable_name1>", "value": "<variable_value1>", "type": "string", "secure": true }, { "name": "<variable_name2>", "value": "<variable_value2>", "type": "bool", "secure": false } ] } ] }
JSON file component description Parameter Description workspace_name
Enter a name for your workspace. The maximum length of character limit is set to 1 MB. For more information, see Designing your workspace structure. terraform_version
The Terraform version that you want to use to run your Terraform code. To use Terraform version 1.4
, enterterraform_v1.4
, and similarlyterraform_v1.5
, andterraform_v1.6
. Make sure that your Terraform config files are compatible with the Terraform version that you specify. If the Terraform variable version is not specified. by default, Schematics selects the version from your template.location
Enter the location where you want to create your workspace. The location determines where your Schematics actions run and where your workspace data is stored. The location is independent from the region where you want to create your IBM Cloud services. description
Enter a description for your workspace. github_source_repo_url
Enter the URL to the GitHub or GitLab repository where your Terraform configuration files are stored. If you choose to create your workspace without a GitHub repository, your workspace is created with a draft state. To connect your workspace to a GitHub repository later, you must use the ibmcloud schematics workspace update
command.variable_name
Optional, enter the name for the input variable that you declared in your Terraform configuration files. variable_type
Optional, enter the data type of your input variable. For supported data types, see the ibmcloud schematics workspace new
command. -
Create the workspace.
ibmcloud schematics workspace new --file workspace.json
-
Verify that your workspace is created. Make sure that your workspace is in an Inactive state.
ibmcloud schematics workspace list
-
Refer to, Managing IBM Cloud resources with Schematics to update or delete IBM Cloud resources with Terraform.
Creating a workspace using API
-
Follow the steps to retrieve your IAM access token and authenticate with IBM Cloud Schematics by using the API.
-
Create the workspace by using Terraform.
curl --request POST --url https://schematics.cloud.ibm.com/v1/workspaces -H "Authorization: <iam_access_token>" -d '{"name": "<workspace_name>","type": ["<terraform_version>"],"location": "<location>","description": "<description>","template_repo": {"url": "<github_source_repo_url>"},"template_data": [{"folder": ".","type": "<terraform_version>","variablestore": [{"value": "<variable_value>","name": "<variable_name>","type": "<variable_type>","secure": true}]}]}'
JSON file component description Parameter Description iam_access_token
Enter the IAM access token that you retrieved in step 1. workspace_name
Enter a name for your workspace. The maximum length of character limit is set to 1 MB. For more information, see Designing your workspace structure. terraform_version
The Terraform version that you want to use to run your Terraform code. Enter terraform_v1.4
to use Terraform version 1.4, and similarlyterraform_v1.5
, andterraform_v1.6
. Make sure that your Terraform config files are compatible with the Terraform version that you specify. If the Terraform variable version is not specified, by default, Schematics selects the version from your template.location
Enter the location where you want to create your workspace. The location determines where your Schematics actions run and where your workspace data is stored. The location is independent from the region where you want to create your IBM Cloud services. description
Enter a description for your workspace. github_source_repo_url
Enter the URL to the GitHub or GitLab repository where your Terraform configuration files are store variable_name
Optional, enter the name for the input variable that you declared in your Terraform configuration files. variable_value
Optional, enter the value for your input variable. variable_type
Optional, enter the data type of your input variable. For supported data types, see the ibmcloud schematics workspace new
command. -
Verify that the workspace is created successfully.
curl -X GET https://schematics.cloud.ibm.com/v1/workspaces -H "Authorization: <iam_access_token>"
-
See Managing IBM Cloud resources with Schematics to update, or delete the IBM Cloud resources.
Creating workspace using Terraform
-
Follow the steps in Setting up Terraform for Schematics to create your workspace with Terraform.
-
See Managing IBM Cloud resources with Schematics to update, or delete the IBM Cloud resources.
Next steps
The next stage of working with workspaces is deploying workspaces.