Quick Start¶
This article will introduce how to use Terraform to create and manage Guance Cloud blacklists.
Prerequisites¶
- Install Terraform, ensuring that the Terraform commands work properly.
- Get API Token
Write Terraform Configuration File¶
Create a file named main.tf
in your project directory:
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:
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:
If the plan executes successfully, you can run the following command to create the resources:
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:
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.