IBM Cloud Docs
Managing resources with Schematics

Managing resources with Schematics

Deploy, modify, and remove IBM Cloud® resources using IBM Cloud Schematics to apply your Terraform templates.

Deploying your resources

Deploy your Terraform configs to provision, or modify your IBM Cloud resources with Schematics.

Before you begin:

To deploy your resources:

  1. From the workspace dashboard, select the workspace for the Terraform template that you want to apply. Sample templates examples are listed in Cloud Schematics GitHub, you can use one of the template for testing. For example, Easy multizone VPC.

  2. Select the Settings tab.

  3. In the Details section, click Pull latest to get the latest version of your Terraform template from the linked GitHub source repository. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command to provide a new version of your template.

  4. Optional: Review the variables that you set for your workspace. The values of your variables are used where ever the you reference the variable in your Terraform template.

  5. Click Generate plan to create a Terraform execution plan. After you click this button, the workspace Jobs page opens and Schematics runs a terraform plan to compare the state of the resources that you already provisioned in your IBM Cloud account with the resources that you want to provision with your Terraform template.

  6. Click Jobs to review the log of your execution plan. The execution plan includes a summary of the IBM Cloud resources that creates, modifies, or deletes to achieve the state that you described in your Terraform template. If you have syntax errors in your Terraform configuration files, you can review the error message in the log file.

  7. Review available service plans and pricing information for each of the IBM Cloud resources that Schematics is about to create or change. Some services come with a limit per IBM Cloud account. If you are about to reach the service limit for your account, the resource is not provisioned until you increase the service quota, or remove existing services first.

  8. When you are ready, apply your Terraform template by clicking Apply plan. This action equals the terraform apply command. After you click the button, IBM Cloud Schematics starts provisioning, modifying, or deleting your IBM Cloud resources based on what actions were identified in the execution plan. Depending on the type and number of resources that you want to provision or modify, this process might take couple of minutes, or even up to hours to complete. During this time, you cannot make changes to your workspace. After all updates are applied, the state of your IBM Cloud resources is stored in a Terraform state file that IBM Cloud Schematics uses to determine what resources exist in your IBM Cloud account.

    If you want to stop applying your Terraform template, you can use the Stop button. Note that all resources that are already created are not removed. If a resource is currently provisioning, Schematics waits for the provisioning to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  9. Review the job log to ensure that no errors occurred during the provisioning, modification, or deletion process.

  10. From the navigation, select Resources to find a summary of IBM Cloud resources that are available in your IBM Cloud account.

Updating your resources

To update IBM Cloud resources, update your Terraform template with the required changes that must be performed on the resources.

Depending on the configuration change, Terraform may not be able to update your resource in place. Instead, Terraform need to first delete the resource and create a new resource. If Terraform identifies a resource to be removed and recreated, make sure that you do not interrupt a working environment, or delete data.

To update your resources:

  1. From the workspace dashboard, select the workspace that points to the Terraform template that you updated.

  2. Select the Settings tab.

  3. In the Details section, click Pull latest to get the latest version of your Terraform template from the linked GitHub source repository. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command to provide a new version of your template.

  4. If you want to change the variable values that you set when you created the workspace, change the variable values.

  5. Click Generate plan to create a Terraform execution plan. Note that during this time, you cannot make changes to your workspace.

  6. Click Jobs to review the log of your execution. The job log provides a summary of all the resources that IBM Cloud Schematics is about to modify. IBM Cloud Schematics might not be able to modify some of your resources, and suggest removing and re-creating the resource.

  7. Click Apply plan to apply the new Terraform template version. Depending on the changes that you made, it might take couple of minutes or up to few hours for the template to be applied. Note that during this time, you cannot make changes to your workspace.

    If you want to stop applying your Terraform template, you can use the Stop button. Note that updates to resources that were already performed are not reverted. If a resource is currently updating, Schematics waits for the update to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  8. Review the job log to ensure that no errors occurred during the modification process.

  9. From the navigation, select Resources and verify that your resources show the updated configuration.

Managing drift between your cloud environment and Terraform configuration

Managing deviations between the real-world state of your cloud environment and your infrastructure code, also referred to as drift, is a key challenge when implementing infrastructure as code. Deviations can happen for many reasons, such as:

  • You added, updated, or removed resources in your Terraform configuration file without running your infrastructure code.
  • You manually added, updated, or removed IBM Cloud without Terraform.
  • You used other automation tools, such as scripts to manipulate the state of your IBM Cloud resources.

Refer to using the workspace drift detection feature.

Reviewing resource and deployment details

View the details of the IBM Cloud Schematics deployments and the IBM Cloud resources that you currently manage with IBM Cloud Schematics.

  1. From the workspace dashboard, select the workspace that you want to inspect.
  2. From the navigation, select Settings to find a summary of activities in your workspace.
  3. Review the logs of previous Terraform execution plans and the plans that you applied.
  4. From the navigation, select Resources to review the state of the IBM Cloud resources that you created with this workspace.
  5. To review who made a change to your Terraform template, go to the source repository in GitHub that is linked to your workspace, and use the built-in capabilities such as the commit history and pull requests to review changes.
  6. To review events that Schematics sent to IBM Cloud Activity Tracker, see IBM Cloud Activity Tracker events.

Removing your resources

To remove an IBM Cloud resource that you provisioned with IBM Cloud Schematics, you can either remove your resources with Schematics, delete your workspace, or remove the infrastructure code in the Terraform template.

Removing an IBM Cloud resource cannot be undone. Make sure that you backed up your data before you remove a resource. If you choose to remove the infrastructure code, or comment out the resource in your Terraform configuration file, make sure to thoroughly review the log file of your execution plan to verify that all your resources are included in the removal.

To remove resources by removing the resource config in your Terraform template:

  1. Open the Terraform configuration file in your source repository in GitHub or on your local machine.

  2. Either remove the infrastructure code from the file, or comment out the resources that you want to remove by adding # to the beginning of each line.

    Example to remove a resource by commenting out a resource definition:

    
    #resource ibm_is_instance "vsi1" {
    #  name    = "${local.BASENAME}-vsi2"
    #  vpc     = ibm_is_vpc.vpc.id
    #  zone    = "${local.ZONE}"
    #  keys    = [data.ibm_is_ssh_key.ssh_key_id.id]
    #  image   = data.ibm_is_image.ubuntu.id
    #  profile = "cc1-2x4"
    
    #  primary_network_interface {
    #    subnet          = ibm_is_subnet.subnet1.id
    #    security_groups = [ibm_is_security_group.sg1.id]
    #  }
    #}
    
  3. Commit the change to your Terraform configuration file.

  4. From the workspace dashboard, select the workspace for the Terraform template that you just changed.

  5. From the navigation, select Settings.

  6. In the Details section, click Pull latest to get the latest version of your Terraform template from the linked GitHub source repository. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command to provide a new version of your template.

  7. Click Generate plan to create a Terraform execution plan. The workspace Jobs page opens. Note that during this time, you cannot make changes to your workspace.

  8. Click Jobs to review the log of your execution plan. The log provides a summary of all the resources that IBM Cloud Schematics is about to remove.

  9. Click Apply plan to remove the IBM Cloud resources from your account.

    If you want to stop applying your Terraform template, you can use the Stop button. Note that all resources that are already removed are not re-created. If a resource is currently deleting, Schematics waits for the deletion to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  10. Review the log files to ensure that no errors occurred during the deletion process.

  11. From the navigation, select Resources and verify that your resources are removed.

  12. Optional: After you removed all your resources, remove your workspace.

    1. Open the workspace dashboard and find the workspace that you want to remove.
    2. Click Actions tab and select Delete workspace option.
    3. Type your workspace name in Type workspace_name to confirm text box.
    4. Click Delete button.

To remove resources using the Schematics console:

  1. From the workspace dashboard, find the workspace that includes the resources that you want to delete.
  2. Click Actions tab and select Destroy resources option.
  3. Type your workspace name in Type workspace_name to confirm text box. Note that destroying resources removes the resources from your workspace and IBM Cloud. This action cannot be undone.
  4. Click Destroy button.
  5. From the navigation, select Jobs to review the logs for your resource deletion. Ensure that no errors occurred during the deletion process.
  6. After successful job execution, from the navigation, select Resources and verify that your resources are removed.

After the removal of your resources is complete, the Schematics workspace can be deleted.

Deploying your resources through CLI

Deploy your Terraform configs to provision, or modify your IBM Cloud resources with Schematics.

Before you begin:

To deploy your resources:

  1. From your local command line interface set up your CLI and Schematics plug-in.

  2. List your workspace by using ibmcloud schematics workspace list command.

  3. Get your workspace by using ibmcloud schematics workspace get command.

  4. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command.

  5. Create Terraform execution plan, by using ibmcloud schematics plan command.

  6. Use your workspace ID to retrieve the logs by using ibmcloud schematics logs command.

  7. When you are ready, execute ibmcloud schematics apply command.

    If you want to stop applying your Terraform template, you can use the ibmcloud schematics job delete command. Note that all resources that are already created are not removed. If a resource is currently provisioning, Schematics waits for the provisioning to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  8. Review the job log to ensure that no errors occurred during the provisioning, modification, or deletion process.

  9. From the navigation pane, select Resources to find a summary of IBM Cloud resources that are available in your IBM Cloud account.

Updating your resources through CLI

To update IBM Cloud resources, update your Terraform template with the required changes that must be performed on the resources.

Depending on the configuration change, Terraform may not be able to update your resource in place. Instead, Terraform need to first delete the resource and create a new resource. If Terraform identifies a resource to be removed and recreated, make sure that you do not interrupt a working environment, or delete data.

To update your resources:

  1. From your command line interface set up your CLI and Schematics plug-in.

  2. List your workspace by using ibmcloud schematics workspace list command.

  3. Get your workspace by using ibmcloud schematics workspace get command.

  4. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command.

  5. Create Terraform execution plan, by using ibmcloud schematics plan command.

  6. Use your workspace ID to retrieve the logs by using ibmcloud schematics logs command.

  7. When you are ready, execute ibmcloud schematics apply command.

    If you want to stop applying your Terraform template, you can use the ibmcloud schematics job delete command. Note that all resources that are already created are not removed. If a resource is currently provisioning, Schematics waits for the provisioning to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  8. Review the job log to ensure that no errors occurred during the provisioning, modification, or deletion process.

  9. From the navigation pane, select Resources to find a summary of IBM Cloud resources that are available in your IBM Cloud account.

Managing drift between your cloud environment and Terraform configuration through CLI

Managing deviations between the real-world state of your cloud environment and your infrastructure code, also referred to as drift, is a key challenge when implementing infrastructure as code. Deviations can happen for many reasons, such as:

  • You added, updated, or removed resources in your Terraform configuration file without running your infrastructure code.
  • You manually added, updated, or removed IBM Cloud without Terraform.
  • You used other automation tools, such as scripts to manipulate the state of your IBM Cloud resources.

Refer to using the workspace drift detection feature.

Reviewing resource and deployment details through CLI

View the details of the IBM Cloud Schematics deployments and the IBM Cloud resources that you currently manage with IBM Cloud Schematics.

  1. From your command line interface set up your CLI and Schematics plug-in.
  2. From the navigation pane, select Resources to find a summary of IBM Cloud resources that are available in your IBM Cloud account.
  3. To review who made a change to your Terraform template, go to the source repository in GitHub that is linked to your workspace, and use the built-in capabilities such as the commit history and pull requests to review changes.
  4. To review events that Schematics sent to IBM Cloud Activity Tracker, see IBM Cloud Activity Tracker events.

Removing your resources through CLI

To remove an IBM Cloud resource that you provisioned with IBM Cloud Schematics, you can either remove your resources with Schematics, delete your workspace, or remove the infrastructure code in the Terraform template.

Removing an IBM Cloud resource cannot be undone. Make sure that you backed up your data before you remove a resource. If you choose to remove the infrastructure code, or comment out the resource in your Terraform configuration file, make sure to thoroughly review the log file of your execution plan to verify that all your resources are included in the removal.

To remove your resources by deleting the infrastructure code from your Terraform template:

  1. Open the Terraform configuration file in your source repository in GitHub or on your local machine.

  2. Either remove the infrastructure code from the file, or comment out the resources that you want to remove by adding # to the beginning of each line.

    Example for commenting out a resource:

    
    #resource ibm_is_instance "vsi1" {
    #  name    = "${local.BASENAME}-vsi2"
    #  vpc     = ibm_is_vpc.vpc.id
    #  zone    = "${local.ZONE}"
    #  keys    = [data.ibm_is_ssh_key.ssh_key_id.id]
    #  image   = data.ibm_is_image.ubuntu.id
    #  profile = "cc1-2x4"
    
    #  primary_network_interface {
    #    subnet          = ibm_is_subnet.subnet1.id
    #    security_groups = [ibm_is_security_group.sg1.id]
    #  }
    #}
    
  3. Commit the change to your Terraform configuration file.

  4. From your command line interface set up your CLI and Schematics plug-in.

  5. Get your workspace by using ibmcloud schematics workspace get command.

  6. If you provided your Terraform template by uploading a tape archive file (.tar), you must use the ibmcloud schematics workspace upload command.

  7. Create Terraform execution plan, by using ibmcloud schematics plan command.

  8. Use your workspace ID to retrieve the logs by using ibmcloud schematics logs command.

  9. When you are ready, execute ibmcloud schematics apply command.

    If you want to stop applying your Terraform template, you can use the ibmcloud schematics job delete command. Note that all resources that are already created are not removed. If a resource is currently provisioning, Schematics waits for the provisioning to complete, and then stops the creation, update, or deletion of any other resources in your Terraform template.

  10. Review the job log to ensure that no errors occurred during the provisioning, modification, or deletion process.

  11. From the navigation pane, select Resources to find a summary of IBM Cloud resources that are available in your IBM Cloud account.

  12. Optional: After you removed all your resources, remove your workspace by using ibmcloud schematics workspace delete command.