Skip to content

Quick Start

This article will guide you on how to use Terraform to create and manage Guance blacklists.

Preparation

Writing the Terraform Configuration File

Create a working directory and create a configuration file named main.tf inside 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-*"]
    }
  ]
}

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

Applying the Configuration

Before applying the configuration, you can first view 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 changes and ask for confirmation. Enter yes to proceed. Once the command executes successfully, you can view the created blacklist in Guance.

Deleting the Resource

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

$ terraform destroy

Similarly, Terraform will ask for confirmation. Enter yes to proceed. Once the command executes successfully, the blacklist will no longer be displayed in Guance.

Feedback

Is this page helpful? ×