Skip to main content

Set up Agent Operator with Terraform

Terraform can be used to create code that provisions all sorts of resources including Kubernetes clusters.

Before you begin

Make sure you have everything you need before you start:

Steps

  1. Create a values file based on the latest version of the YAML file found here.

  2. Name it contrast-agent-operator.yaml.

  3. Add agent keys to the clusterDefaults section of the YAML file. You will also need to set the enabled: property to true.

    clusterDefaults:
      enabled: true
      url: YOUR_CONTRAST_URL
      apiKeyValue: YOUR_API_KEY
      serviceKeyValue: YOUR_AGENT_SERVICE_KEY
      userNameValue: YOUR_AGENT_USERNAME
      yaml: |-
        enable: true
  4. Label your deployments by using the values from the table.

    Tip

    Run the kubectl get deployments command to also find the deployment names.

    Example commands for labeling a deployment via CLI:

    Run:

    kubectl get deployments

    Get an output (for example):

    NAME                READY   UP-TO-DATE   AVAILABLE   AGE
    app1-deployment     0/3     0            0           1s

    Then run the following command:

    kubectl label deployment app1-deployment contrast-agent=java

    Updating your Helm chart for the application being deployed is highly recommended.

  5. Add the following Terraform code:

    resource "helm_release" "contrast-agent-operator" {  
        name       = "contrast-agent-operator"  
        repository = "https://contrastsecurity.dev/helm-charts"  
        chart      = "contrast-agent-operator"  
        values = [    
        file("${path.module}/contrast-agent-operator.yaml")  
        ]
    }

    You can use the values in this table.

Note

If the YAML file is edited any time after this setup, you will need to repeat all of the steps above to get the Operator properly running again. Run the terraform apply command after step 5.