Quick Start¶
This article will introduce how to use Terraform to create and manage Guance blacklists.
Preparation¶
- Install Terraform, ensuring that the Terraform command works properly.
- Obtain API Token
Write Terraform Configuration File¶
Create a working directory, and within it, create a configuration file named 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:
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:
If the plan executes successfully, you can run the following command to create resources:
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:
Similarly, Terraform will request confirmation; type yes
to continue execution. After the command executes successfully, the blacklist will no longer be displayed in Guance.