Skip to content

Commit

Permalink
feat(LTS): import LTS resource, unit test and document
Browse files Browse the repository at this point in the history
  • Loading branch information
Zippo-Wang committed Dec 28, 2023
1 parent 5073314 commit f5fcfdd
Show file tree
Hide file tree
Showing 22 changed files with 3,727 additions and 2 deletions.
48 changes: 48 additions & 0 deletions docs/data-sources/lts_structuring_custom_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
subcategory: "Log Tank Service (LTS)"
---

# g42cloud_lts_structuring_custom_templates

Use this data source to get the list of LTS structuring custom templates.

## Example Usage

```hcl
data "g42cloud_lts_structuring_custom_templates" "test" {
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `template_id` - (Optional, String) Specifies the custom template ID to be queried.

* `name` - (Optional, String) Specifies the custom template name to be queried.

* `type` - (Optional, String) Specifies the custom template type to be queried. Valid values are: **regex**, **json**,
**split** and **nginx**.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `templates` - The list of LTS structuring custom templates.
The [templates](#CustomTemplates_templates) structure is documented below.

<a name="CustomTemplates_templates"></a>
The `templates` block supports:

* `id` - The structuring custom template ID.

* `name` - The structuring custom template name.

* `type` - The structuring custom template type.

* `demo_log` - The sample log event.
152 changes: 152 additions & 0 deletions docs/resources/lts_aom_access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
subcategory: "Log Tank Service (LTS)"
---

# g42cloud_lts_aom_access

Manages an AOM to LTS log mapping rule resource within G42Cloud.

## Example Usage

### Creating with all workloads

```hcl
variable "cluster_id" {}
variable "cluster_name" {}
variable "log_group_id" {}
variable "log_group_name" {}
variable "log_stream_id" {}
variable "log_stream_name" {}
resource "g42cloud_lts_aom_access" "test" {
name = "test_name"
cluster_id = var.cluster_id
cluster_name = var.cluster_name
namespace = "default"
workloads = ["__ALL_DEPLOYMENTS__"]
access_rules {
file_name = "/test/*"
log_group_id = var.log_group_id
log_group_name = var.log_group_name
log_stream_id = var.log_stream_id
log_stream_name = var.log_stream_name
}
access_rules {
file_name = "/demo/demo.log"
log_group_id = var.log_group_id
log_group_name = var.log_group_name
log_stream_id = var.log_stream_id
log_stream_name = var.log_stream_name
}
}
```

### Creating with specify workloads

```hcl
variable "cluster_id" {}
variable "cluster_name" {}
variable "log_group_id" {}
variable "log_group_name" {}
variable "log_stream_id" {}
variable "log_stream_name" {}
variable "workload" {}
resource "g42cloud_lts_aom_access" "test" {
name = "test_name"
cluster_id = var.cluster_id
cluster_name = var.cluster_name
namespace = "default"
workloads = [var.workload]
access_rules {
file_name = "__ALL_FILES__"
log_group_id = var.log_group_id
log_group_name = var.log_group_name
log_stream_id = var.log_stream_id
log_stream_name = var.log_stream_name
}
}
```

### Creating with CCI cluster

```hcl
variable "log_group_id" {}
variable "log_group_name" {}
variable "log_stream_id" {}
variable "log_stream_name" {}
resource "g42cloud_lts_aom_access" "test" {
name = "test_name"
cluster_id = "CCI-ClusterID"
cluster_name = "CCI-Cluster"
namespace = "default"
workloads = ["__ALL_DEPLOYMENTS__"]
access_rules {
file_name = "__ALL_FILES__"
log_group_id = var.log_group_id
log_group_name = var.log_group_name
log_stream_id = var.log_stream_id
log_stream_name = var.log_stream_name
}
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `name` - (Required, String) Specifies the unique rule name. The name consists of 1 to 100 characters,
including letters, digits, underscores (_), hyphens (-) and dots (.).

* `cluster_id` - (Required, String) Specifies the CCE or CCI cluster ID. It is fixed to **CCI-ClusterID** for CCI.

* `cluster_name` - (Required, String) Specifies the CCE or CCI cluster name. It is fixed to **CCI-Cluster** for CCI.

* `namespace` - (Required, String) Specifies the namespace.

* `workloads` - (Required, List) Specifies the workloads.
+ When creating with all workloads, this field should be `["__ALL_DEPLOYMENTS__"]`.
+ When creating with specify workloads, this field should be the list of workloads.

* `access_rules` - (Required, List) Specifies the access log details.
The [access_rules](#AOMAccess_access_rules) structure is documented below.

* `container_name` - (Optional, String) Specifies the container name.

<a name="AOMAccess_access_rules"></a>
The `access_rules` block supports:

* `file_name` - (Required, String) Specifies the path name.
+ When collecting access all logs, set this field to `__ALL_FILES__`.
+ When collecting specify log paths, the matching rule should be `^\/[A-Za-z0-9.*_\/-]+|stdout\.log|`, such as
`/test/*` or `/test/demo.log`. Up to two asterisks (*) are allowed.

* `log_group_id` - (Required, String) Specifies the log group ID.

* `log_group_name` - (Required, String) Specifies the log group name.

* `log_stream_id` - (Required, String) Specifies the log stream ID.

* `log_stream_name` - (Required, String) Specifies the log stream name.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

## Import

The AOM to LTS log mapping rule can be imported using the `id`, e.g.

```bash
$ terraform import g42cloud_lts_aom_access.test <id>
```
156 changes: 156 additions & 0 deletions docs/resources/lts_host_access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
subcategory: "Log Tank Service (LTS)"
---

# g42cloud_lts_host_access

Manages an LTS host access resource within G42Cloud.

## Example Usage

```hcl
variable "group_id" {}
variable "stream_id" {}
variable "host_group_id" {}
resource "g42cloud_lts_host_access" "test" {
name = "access-demo"
log_group_id = var.group_id
log_stream_id = var.stream_id
host_group_ids = [ var.host_group_id ]
access_config {
paths = ["/var/log/*"]
black_paths = ["/var/log/*/a.log"]
single_log_format {
mode = "system"
}
}
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `name` - (Required, String, ForceNew) Specifies the host access name. The name consists of 1 to 64 characters.
Only letters, digits, underscores (_), and periods (.) are allowed, and the period cannot be the first or last character.
Changing this parameter will create a new resource.

* `log_group_id` - (Required, String, ForceNew) Specifies the log group ID.
Changing this parameter will create a new resource.

* `log_stream_id` - (Required, String, ForceNew) Specifies the log stream ID.
Changing this parameter will create a new resource.

* `access_config` - (Required, List) Specifies the configurations of host access.
The [access_config](#HostAccessConfigDeatil) structure is documented below.

* `host_group_ids` - (Optional, List) Specifies the log access host group ID list.

* `tags` - (Optional, Map) Specifies the key/value to attach to the host access.

<a name="HostAccessConfigDeatil"></a>
The `access_config` block supports:

* `paths` - (Required, List) Specifies the collection paths.

+ A path must start with `/` or `Letter:\`.
+ A path cannot contain only slashes (/). The following special characters are not allowed: <>'|"
+ A path cannot start with `/**` or `/*`.
+ Only one double asterisk (**) can be contained in a path.
+ Up to 10 paths can be specified.

* `black_paths` - (Optional, List) Specifies the collection path blacklist.

+ A path must start with `/` or `Letter:\`.
+ A path cannot contain only slashes (/). The following special characters are not allowed: <>'|"
+ A path cannot start with `/**` or `/*`.
+ Only one double asterisk (**) can be contained in a path.
+ Up to 10 paths can be specified.

-> If you blacklist a file or directory that has been set as a collection path, the blacklist settings
will be used and the file or files in the directory will be filtered out.

* `single_log_format` - (Optional, List) Specifies the configuration single-line logs. Each log line is displayed as a
single log event. The [single_log_format](#HostAccessConfigSingleLogFormat) structure is documented below.

* `multi_log_format` - (Optional, List) Specifies the configuration multi-line logs. Multiple lines of exception log events
can be displayed as a single log event. This is helpful when you check logs to locate problems.
The [multi_log_format](#HostAccessConfigMultiLogFormat) structure is documented below.

* `windows_log_info` - (Optional, List) Specifies the configuration of Windows event logs.
The [windows_log_info](#HostAccessConfigWindowsLogInfo) structure is documented below.

<a name="HostAccessConfigSingleLogFormat"></a>
The `single_log_format` blocks supports:

* `mode` - (Required, String) Specifies mode of single-line log format. The options are as follows:
+ **system**: the system time.
+ **wildcard**: the time wildcard.

* `value` - (Optional, String) Specifies value of single-line log format.
+ If mode is **system**, the value is the current timestamp, the number of milliseconds elapsed since January 1, 1970 UTC.
+ If mode is **wildcard**, the value is **required** and is a time wildcard, which is used to look for the log printing
time as the beginning of a log event. If the time format in a log event is `2019-01-01 23:59:59`, the time wildcard is
**YYYY-MM-DD hh:mm:ss**. If the time format in a log event is `19-1-1 23:59:59`, the time wildcard is **YY-M-D hh:mm:ss**.

<a name="HostAccessConfigMultiLogFormat"></a>
The `multi_log_format` blocks supports:

* `mode` - (Required, String) Specifies mode of multi-line log format. The options are as follows:
+ **time**: the time wildcard.
+ **regular**: the regular expression.

* `value` - (Required, String) Specifies value of multi-line log format.
+ If mode is **regular**, the value is a regular expression.
+ If mode is **time**, the value is a time wildcard, which is used to look for the log printing time as the beginning
of a log event. If the time format in a log event is `2019-01-01 23:59:59`, the time wildcard is **YYYY-MM-DD hh:mm:ss**.
If the time format in a log event is `19-1-1 23:59:59`, the time wildcard is **YY-M-D hh:mm:ss**.

-> The time wildcard and regular expression will look for the specified pattern right from the beginning of each log line.
If no match is found, the system time, which may be different from the time in the log event, is used. In general cases,
you are advised to select **Single-line** for Log Format and **system** time for Log Time.

<a name="HostAccessConfigWindowsLogInfo"></a>
The `windows_log_info` block supports:

* `categorys` - (Required, List) Specifies the types of Windows event logs to collect. The valid values are
**Application**, **System**, **Security** and **Setup**.

* `event_level` - (Required, List) Specifies the Windows event severity. The valid values are **information**, **warning**,
**error**, **critical** and **verbose**. Only Windows Vista or later is supported.

* `time_offset_unit` - (Required, String) Specifies the collection time offset unit. The valid values are
**day**, **hour** and **sec**.

* `time_offset` - (Required, Int) Specifies the collection time offset. This time takes effect only for the first
time to ensure that the logs are not collected repeatedly.

+ When `time_offset_unit` is set to **day**, the value ranges from 1 to 7 days.
+ When `time_offset_unit` is set to **hour**, the value ranges from 1 to 168 hours.
+ When `time_offset_unit` is set to **sec**, the value ranges from 1 to 604800 seconds.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the host access.

* `access_type` - The log access type.

* `log_group_name` - The log group name.

* `log_stream_name` - The log stream name.

## Import

The host access can be imported using the `name`, e.g.

```bash
$ terraform import g42cloud_lts_host_access.test access-demo
```
Loading

0 comments on commit f5fcfdd

Please sign in to comment.