Quick Start¶
This article will introduce how to use Terraform to create and manage Guance blacklists.
Prepare¶
- Install Terraform, ensure the Terraform command works properly.
- Obtain an API Token
Write Terraform Configuration File¶
Create a working directory and create a configuration file named main.tf
inside it.
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 the Terraform plugin and set up the local working directory.
Apply Configuration¶
Before applying the configuration, you can first view the execution plan of what Terraform will do:
If the plan executes successfully, you can run the following command to create resources:
Terraform will display information about the planned changes and ask for confirmation. Type yes
to proceed. 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 prompt for confirmation; type yes
to continue. Once the command executes successfully, the blacklist will no longer appear in Guance.