Skip to content

Commit

Permalink
feat(cfw): add some detailed region fields to CFW log type data source
Browse files Browse the repository at this point in the history
  • Loading branch information
profoundwu committed Aug 15, 2024
1 parent 3158721 commit d3640d9
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 159 deletions.
46 changes: 35 additions & 11 deletions docs/data-sources/cfw_access_control_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Use this data source to get the list of CFW access control logs.
## Example Usage

```hcl
variable "fw_instance_id" {}
variable "start_time" {}
variable "end_time" {}
data "huaweicloud_cfw_access_control_logs" "test" {
fw_instance_id = var.fw_instance_id
start_time = var.start_time
end_time = var.end_time
variable "fw_instance_id" {}
variable "start_time" {}
variable "end_time" {}
data "huaweicloud_cfw_access_control_logs" "test" {
fw_instance_id = var.fw_instance_id
start_time = var.start_time
end_time = var.end_time
}
```

Expand Down Expand Up @@ -49,7 +49,7 @@ The following arguments are supported:

* `app` - (Optional, String) Specifies the application protocol.

* `enterprise_project_id` - (Optional, String) Specifies the enterprise project id.
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID.

* `rule_name` - (Optional, String) Specifies the rule name.

Expand All @@ -59,6 +59,14 @@ The following arguments are supported:

* `dst_region_name` - (Optional, String) Specifies the destination region name.

* `src_province_name` - (Optional, String) Specifies the source province name.

* `dst_province_name` - (Optional, String) Specifies the destination province name.

* `src_city_name` - (Optional, String) Specifies the source city name.

* `dst_city_name` - (Optional, String) Specifies the destination city name.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:
Expand Down Expand Up @@ -94,12 +102,28 @@ The `records` block supports:

* `action` - The action.

* `src_region_id` - The source region id.
* `src_region_id` - The source region ID.

* `src_region_name` - The source region name.

* `dst_region_id` - The destination region id.
* `dst_region_id` - The destination region ID.

* `dst_region_name` - The destination region name.

* `src_province_id` - The source province ID.

* `src_province_name` - The source province name.

* `src_city_id` - The source city ID.

* `src_city_name` - The source city name.

* `dst_province_id` - The destination province ID.

* `dst_province_name` - The destination province name.

* `dst_city_id` - The destination city ID.

* `dst_city_name` - The destination city name.

* `dst_host` - The destination host.
24 changes: 24 additions & 0 deletions docs/data-sources/cfw_attack_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ The following arguments are supported:

* `dst_region_name` - (Optional, String) Specifies the destination region name.

* `src_province_name` - (Optional, String) Specifies the source province name.

* `dst_province_name` - (Optional, String) Specifies the destination province name.

* `src_city_name` - (Optional, String) Specifies the source city name.

* `dst_city_name` - (Optional, String) Specifies the destination city name.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:
Expand Down Expand Up @@ -127,6 +135,22 @@ The `records` block supports:

* `dst_region_name` - The destination region name.

* `src_province_id` - The source province ID.

* `src_province_name` - The source province name.

* `src_city_id` - The source city ID.

* `src_city_name` - The source city name.

* `dst_province_id` - The destination province ID.

* `dst_province_name` - The destination province name.

* `dst_city_id` - The destination city ID.

* `dst_city_name` - The destination city name.

<a name="records_packet_messages_struct"></a>
The `packet_messages` block supports:

Expand Down
30 changes: 27 additions & 3 deletions docs/data-sources/cfw_flow_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ The following arguments are supported:

* `dst_region_name` - (Optional, String) Specifies the destination region name.

* `src_province_name` - (Optional, String) Specifies the source province name.

* `dst_province_name` - (Optional, String) Specifies the destination province name.

* `src_city_name` - (Optional, String) Specifies the source city name.

* `dst_city_name` - (Optional, String) Specifies the destination city name.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:
Expand Down Expand Up @@ -98,10 +106,26 @@ The `records` block supports:

* `dst_host` - The destination host.

* `src_region_id` - The source region ID.

* `src_region_name` - The source region name.

* `dst_region_id` - The destination region ID.

* `dst_region_name` - The destination region name.

* `src_region_id` - The source region id.
* `src_province_id` - The source province ID.

* `dst_region_id` - The destination region id.
* `src_province_name` - The source province name.

* `src_region_name` - The source region name.
* `src_city_id` - The source city ID.

* `src_city_name` - The source city name.

* `dst_province_id` - The destination province ID.

* `dst_province_name` - The destination province name.

* `dst_city_id` - The destination city ID.

* `dst_city_name` - The destination city name.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ func TestAccDataSourceCfwAccessControlLogs_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSource, "records.0.src_region_name"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.dst_region_name"),

resource.TestCheckOutput("app_filter_is_useful", "true"),
resource.TestCheckOutput("action_filter_is_useful", "true"),
resource.TestCheckOutput("src_port_filter_is_useful", "true"),
resource.TestCheckOutput("dst_port_filter_is_useful", "true"),
resource.TestCheckOutput("src_region_name_filter_is_useful", "true"),
resource.TestCheckOutput("dst_region_name_filter_is_useful", "true"),
resource.TestCheckOutput("is_app_filter_useful", "true"),
resource.TestCheckOutput("is_action_filter_useful", "true"),
resource.TestCheckOutput("is_src_port_filter_useful", "true"),
resource.TestCheckOutput("is_dst_port_filter_useful", "true"),
resource.TestCheckOutput("is_src_region_name_filter_useful", "true"),
resource.TestCheckOutput("is_dst_region_name_filter_useful", "true"),
resource.TestCheckOutput("is_dst_province_name_filter_useful", "true"),
),
},
},
Expand All @@ -56,13 +57,14 @@ data "huaweicloud_cfw_access_control_logs" "test" {
}
locals {
records = data.huaweicloud_cfw_access_control_logs.test.records
app = local.records[0].app
action = local.records[0].action
src_port = local.records[0].src_port
dst_port = local.records[0].dst_port
src_region_name = local.records[0].src_region_name
dst_region_name = local.records[0].dst_region_name
records = data.huaweicloud_cfw_access_control_logs.test.records
app = local.records[0].app
action = local.records[0].action
src_port = local.records[0].src_port
dst_port = local.records[0].dst_port
src_region_name = local.records[0].src_region_name
dst_region_name = local.records[0].dst_region_name
dst_province_name = local.records[0].dst_province_name
}
data "huaweicloud_cfw_access_control_logs" "filter_by_app" {
Expand Down Expand Up @@ -107,49 +109,63 @@ data "huaweicloud_cfw_access_control_logs" "filter_by_dst_region_name" {
dst_region_name = local.dst_region_name
}
data "huaweicloud_cfw_access_control_logs" "filter_by_dst_province_name" {
fw_instance_id = "%[1]s"
start_time = "%[2]s"
end_time = "%[3]s"
dst_province_name = local.dst_province_name
}
locals {
records_by_app = data.huaweicloud_cfw_access_control_logs.filter_by_app.records
records_by_action = data.huaweicloud_cfw_access_control_logs.filter_by_action.records
records_by_src_port = data.huaweicloud_cfw_access_control_logs.filter_by_src_port.records
records_by_dst_port = data.huaweicloud_cfw_access_control_logs.filter_by_dst_port.records
records_by_src_region_name = data.huaweicloud_cfw_access_control_logs.filter_by_src_region_name.records
records_by_dst_region_name = data.huaweicloud_cfw_access_control_logs.filter_by_dst_region_name.records
records_by_app = data.huaweicloud_cfw_access_control_logs.filter_by_app.records
records_by_action = data.huaweicloud_cfw_access_control_logs.filter_by_action.records
records_by_src_port = data.huaweicloud_cfw_access_control_logs.filter_by_src_port.records
records_by_dst_port = data.huaweicloud_cfw_access_control_logs.filter_by_dst_port.records
records_by_src_region_name = data.huaweicloud_cfw_access_control_logs.filter_by_src_region_name.records
records_by_dst_region_name = data.huaweicloud_cfw_access_control_logs.filter_by_dst_region_name.records
records_by_dst_province_name = data.huaweicloud_cfw_access_control_logs.filter_by_dst_province_name.records
}
output "app_filter_is_useful" {
output "is_app_filter_useful" {
value = length(local.records_by_app) > 0 && alltrue(
[for v in local.records_by_app[*].app : v == local.app]
)
}
output "action_filter_is_useful" {
output "is_action_filter_useful" {
value = length(local.records_by_action) > 0 && alltrue(
[for v in local.records_by_action[*].action : v == local.action]
)
}
output "src_port_filter_is_useful" {
output "is_src_port_filter_useful" {
value = length(local.records_by_src_port) > 0 && alltrue(
[for v in local.records_by_src_port[*].src_port : v == local.src_port]
)
}
output "dst_port_filter_is_useful" {
output "is_dst_port_filter_useful" {
value = length(local.records_by_dst_port) > 0 && alltrue(
[for v in local.records_by_dst_port[*].dst_port : v == local.dst_port]
)
}
output "src_region_name_filter_is_useful" {
output "is_src_region_name_filter_useful" {
value = length(local.records_by_src_region_name) > 0 && alltrue(
[for v in local.records_by_src_region_name[*].src_region_name : v == local.src_region_name]
)
}
output "dst_region_name_filter_is_useful" {
output "is_dst_region_name_filter_useful" {
value = length(local.records_by_dst_region_name) > 0 && alltrue(
[for v in local.records_by_dst_region_name[*].dst_region_name : v == local.dst_region_name]
)
}
output "is_dst_province_name_filter_useful" {
value = length(local.records_by_dst_province_name) > 0 && alltrue(
[for v in local.records_by_dst_province_name[*].dst_province_name : v == local.dst_province_name]
)
}
`, acceptance.HW_CFW_INSTANCE_ID, acceptance.HW_CFW_START_TIME, acceptance.HW_CFW_END_TIME)
}
Loading

0 comments on commit d3640d9

Please sign in to comment.