Skip to content

Quick Start

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

Prerequisites

Write Terraform Configuration File

Create a file named main.tf in your project directory:

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

Open main.tf 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>" # 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 any necessary provider plugins and set up the local working directory.

Apply the Configuration

Before applying the configuration, you can first review the plan of actions Terraform is going to execute:

$ terraform plan

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

$ terraform apply

Terraform will display a summary of planned changes and request confirmation. Enter yes to proceed. After the command executes successfully, you can view the created blacklist in Guance Cloud Console.

Destroy the Resources

When you no longer need the resources, you can destroy them by running the following command:

$ terraform destroy

Similarly, Terraform will prompt for confirmation; enter yes to proceed with the execution. After the command executes successfully, the blacklist will no longer be displayed in Guance Cloud.

Feedback

Is this page helpful? ×