Skip to content

Quick Start

This article will introduce how to use Terraform to create and manage TrueWatch blacklists.

Preparation

Write Terraform Configuration File

Create a working directory and create a configuration file named main.tf in it.

$ mkdir learn-terraform-pipeline && cd $_
$ touch main.tf

Open the main.tf file and add the following content:

terraform {
  required_version = ">=0.12"

  required_providers {
    guance = {
      source = "GuanceCloud/guance"
      version = "~> 0.0.6"
    }
  }
}

provider "guance" {
  access_token = "<API Token>" # Replace with your own API Token
  region = "hangzhou"
}

resource "guance_blacklist" "demo" {
  name = "blacklist-demo"
  type   = "logging"
  sources = ["mysql", "oracle"]
  desc = "this is a demo"

  filters = [
    {
      name      = "foo1"
      operation = "in"
      condition = "and"
      values    = ["oac-*"]
    }
  ]
}

Initialize Terraform

Run the following command to initialize Terraform:

$ terraform init

This will download and install the Terraform plugin and set up the local working directory.

Apply Configuration

Before applying the configuration, you can first check the execution plan that Terraform will perform:

$ terraform plan

If the plan executes successfully, you can run the following command to create the resource:

$ terraform apply

Terraform will display the planned resource changes and ask for confirmation. Enter yes to continue. After the command is successfully executed, you can view the created blacklist in TrueWatch.

Delete Resource

When you no longer need this blacklist, you can use the following command to destroy the resource:

$ terraform destroy

Similarly, Terraform will ask for confirmation, enter yes to continue. After the command is successfully executed, the blacklist will no longer be displayed in TrueWatch.