IBM Cloud Docs
Creating workspaces and importing your Terraform

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

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

  1. Log in to IBM Cloud.
  2. Access Schematics > Workspaces > Create workspace.
    • In Specify Template section:
      • GitHub, GitLab, or Bitbucket repository URL - <provide your Terraform Git repository URL.

      • Personal access token - <leave it blank>.

      • Terraform Version - terraform_v1.0. You need to select Terraform version 1.0 or greater version. For example, if your Terraform templates are created by using Terraform v1.0, select the Terraform version parameter as terraform_v1.0. You can select Terraform_v1.1 to use Terraform version 1.1, terraform_v1.0 to use Terraform version 1.0. When you specify terraform_v1.1 means that users can have Terraform v1.1.0, v1.1.1, or v1.1.2, so on. Schematics supports Terraform_v1.x and also plans to make releases available after 30 to 45 days of HashiCorp Configuration Language (HCL) release.

        Schematics supports the current release of Terraform v1.1, through terraform_v1.0. The Terraform must use the version constraint, such as > or >= or ~> for the required_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.
    • Click Create. Your workspace is created with a Draft state and the workspace Settings page opens.

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.

  1. On the workspace Settings page, enter the edit icon to edit your Repository URL. The link can point to the master 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
  2. 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. For more information, see Creating a personal access token for the command-line. If you want to clone from the Git repository see the allowed and blocked file extensions for cloning.

  3. Select the Terraform version that your Terraform configuration files are written in.

  4. Click the checkbox I understand the changes that could happen if I edit this URL and I agree to these happening option.

  5. 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 as discarded. 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.

  6. 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

  1. 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 0.12, enter terraform_v0.12, and similarly terraform_v0.13, and terraform_v0.14. 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.
  2. Create the workspace.

    ibmcloud schematics workspace new --file workspace.json
    
  3. Verify that your workspace is created. Make sure that your workspace is in an Inactive state.

    ibmcloud schematics workspace list
    
  4. Refer to, Managing IBM Cloud resources with Schematics to update or delete IBM Cloud resources with Terraform.

Creating a workspace using API

  1. Follow the steps to retrieve your IAM access token and authenticate with IBM Cloud Schematics by using the API.

  2. 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_v0.12 to use Terraform version 0.12, and similarly terraform_v0.13, and terraform_v0.14. 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.
  3. Verify that the workspace is created successfully.

    curl -X GET https://schematics.cloud.ibm.com/v1/workspaces -H "Authorization: <iam_access_token>"
    
  4. See Managing IBM Cloud resources with Schematics to update, or delete the IBM Cloud resources.

Creating workspace using Terraform

  1. Follow the steps in Setting up Terraform for Schematics to create your workspace with Terraform.

  2. 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.