IBM Cloud Docs
Set up your DevSecOps infrastructure and CI toolchain for deploying a secure app

Set up your DevSecOps infrastructure and CI toolchain for deploying a secure app

Use this tutorial for automated setup and provisioning of the infrastructure for your CI and CD toolchains by using a Terraform-based quick start template. The template uses DevSecOps best practices of compliance and security. The template uses an IBM Cloud® Schematics workspace, which automates the creation of the required infrastructure for securely deploying your app to either Kubernetes or Red Hat® OpenShift®. The template uses the DevSecOps IBM Cloud® Continuous Delivery toolchain pipeline structure. The toolchain is preconfigured for continuous delivery with inventory integration, change management, evidence collection, and deployment.

IBM Cloud Schematics delivers Terraform-as-a-Service so that you can use a high-level scripting language to model the resources that you want in your IBM Cloud environment, and enable Infrastructure as Code (IaC). Terraform is open source software that is developed by HashiCorp. Terraform enables predictable and consistent resource provisioning to rapidly build complex, multitier cloud environments.

In this tutorial, you follow three easy steps to create a Schematics workspace, apply a Terraform execution plan, and update the environment properties value. When you apply the plan, the Schematics workspace sets up your secure infrastructure. This infrastructure is shareable with your team, and it works for the DevSecOpsA methodology that integrates security practices with the software development and operations lifecycle. The goal of the merge is to prioritize the balance of development speed and security. CI and CD toolchain templates.

The automated infrastructure setup creates resources that are automatically provisioned by using the default values from the DevSecOps CI and CD templates. You can find the default values in the Variables section of the Schematics workspace. The following resources are created:

Before you begin

Create a Schematics workspace

  1. Click one of the following options for the cluster deployment target. This action takes you to the Deploy to IBM Cloud page where you create a Schematics workspace. Complete the required fields on that page, and then click Next.

    Deploy to Kubernetes on IBM Cloud

    Deploy to OpenShift on IBM Cloud

    Based on which option you select, the corresponding Terraform template from this repository is automatically imported into the new Schematics workspace.

  2. Verify the information, and then click Create. The Schematics workspace is created, and the Settings page for the Schematics workspace is displayed.

Apply the Terraform execution plan

  1. In the Variables section of the Schematics Settings page, enter the values for each variable. Required fields don't have default values. You can override default values.

    If you override the sm_service_name value, the Terraform execution plan uses the existing resource instead of creating a new resource.

  2. For the gitlab_token variable, enter the personal access token that you obtained previously.

  3. For the ibmcloud_api_key variable, enter the IBM Cloud API key that you obtained previously.

  4. For the registry_namespace variable, enter a container registry namespace value. To create a namespace, see Container Registry Namespaces.

  5. For the kube_version variable, run: ibmcloud ks versions on a command line to see available versions.

  6. Optional. If you already have a Secrets Manager instance, enter it name for the sm_service_name variable. Otherwise, don't change this variable.

  7. Optional. If you want to adjust the size or location of your cluster, you can override the following variables: datacenter, default_pool_size, machine_type, hardware, public_vlan_num, or private_vlan_num (the default values are for the dal12/us-south datacenter).

  8. Optional. Click Generate plan. This action creates a Terraform execution plan and checks your configuration for syntax errors. On the Schematics Jobs page, you can review log files for errors and IBM Cloud resources that must be created, modified, or deleted to achieve the correct state of the Terraform template.

  9. After you enter all the values for the variables and are satisfied with the changes, click Apply plan to run your infrastructure code.

    This step takes some time to complete (usually 20 - 30 minutes, but it can take longer), due to the creation of a new Kubernetes or OpenShift cluster.

  10. On the Schematics Jobs page, you can view the log by expanding the job name.

  11. After the plan is applied, view the URL to the generated IBM Cloud DevSecOps CI toolchain. The URL is located near the end of the log file on a line that begins with View the toolchain at:.

If you apply your plan a second time, the previously created Kubernetes or OpenShift cluster and any applications that are deployed to it are deleted, and a new cluster is created. However, if you override the default cluster name, that cluster is used.

Deploy the app

Follow these steps to run the pipeline.

  1. Go to your newly created DevSecOps CI toolchain.
  2. Click the Git tile that starts with compliance-app.
  3. To trigger the pr-pipeline, update some text in the README.md file, and then start a PR against the main branch.
  4. In the Target Branch field, change the branch name from main to something else. For example, mybranch.
  5. Ensure that the "Start a new merge request with these changes" checkbox is selected.
  6. Click Commit changes.
  7. Optional. On the New merge request page, add a description.
  8. Click Create merge request.

The pr-pipeline in the ci-toolchain is triggered. Verify that the pipeline is running by completing these steps:

  1. Return to your CI toolchain, and click the Delivery Pipeline tile for your pr-pipeline. On the pr-pipeline Dashboard page, you can see the pr-pipeline running.

  2. To view the progress, click the pr-pipeline link.

    pr-pipeline
    Figure 1. pr-pipeline Dashboard

Notes:

  1. If any vulnerabilities are found, then the code-pr-finish step fails.

  2. To find the vulnerabilities, go to the code-unit-tests > run-stage to view the logs. (screenshot)

  3. Solve the vulnerabilities, and then the pr-pipeline is triggered.

  4. Go back to the app repo tile.

  5. In the nav pane, click Merge requests.

  6. Select the PR.

  7. Optional. Click the Approve button (If not you see an error at the end of the ci-pipeline run).

  8. Select "Delete source branch."

  9. Click Merge.

Merging this PR automatically triggers the ci-pipeline. To verify, go back to the ci-pipeline tile in the toolchain and verify that the pipeline is running. Click the pipeline link to see the progress.

This step deploys the app to the newly created cluster. The Application URL can be found at the bottom of the log file in the deploy-dev > run-stage step of the ci-pipeline.

Next steps

Continue to the "Explore your CI toolchain" section of the next tutorial, and run the CI-PR and CI pipelines. Then, continue through the remainder of the steps in that tutorial to deploy a secure app.

At any time, you can view all the resources that were created with this tutorial by clicking the Menu icon Menu icon and selecting Resource list. You can view your Schematics workspace, cluster, IBM Cloud Object Storage instance, Secrets Manager service, continuous delivery service, and toolchain.