Skip to content

Quick Start

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

Preparation

Write Terraform Configuration File

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

$ 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 Terraform plugins and set up the local working directory.

Apply Configuration

Before applying the configuration, you can first view the operation plan that Terraform is going to execute:

$ terraform plan

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

$ terraform apply

Terraform will display information about the planned changes to resources and request confirmation. Type yes to continue execution. After the command executes successfully, you can view the created blacklist in Guance.

Delete Resources

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

$ terraform destroy

Similarly, Terraform will request confirmation; type yes to continue execution. After the command executes successfully, the blacklist will no longer be displayed in Guance.

Feedback

Is this page helpful? ×