Skip to content

Commit bfc3c8a

Browse files
feat(hss): support hss_container_network_cluster_sync resource (#8403)
1 parent 72a9d65 commit bfc3c8a

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
subcategory: "Host Security Service (HSS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_hss_container_network_cluster_sync"
5+
description: |-
6+
Manages an HSS container network cluster sync resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_hss_container_network_cluster_sync
10+
11+
Manages an HSS container network cluster sync resource within HuaweiCloud.
12+
13+
-> This resource is a one-time action resource using to sync HSS container network cluster. Deleting this resource will
14+
not clear the corresponding request record, but will only remove the resource information from the tf state file.
15+
16+
## Example Usage
17+
18+
```hcl
19+
resource "huaweicloud_hss_container_network_cluster_sync" "test" {}
20+
```
21+
22+
## Argument Reference
23+
24+
The following arguments are supported:
25+
26+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
27+
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.
28+
29+
* `enterprise_project_id` - (Optional, String, NonUpdatable) Specifies the enterprise project ID.
30+
This parameter is valid only when the enterprise project is enabled.
31+
The default value is **0**, indicating the default enterprise project.
32+
If it is necessary to operate the asset under all enterprise projects, the value is **all_granted_eps**.
33+
If you only have permissions for a specific enterprise project, you need set the enterprise project ID. Otherwise,
34+
the operation may fail due to insufficient permissions.
35+
36+
## Attributes Reference
37+
38+
In addition to all arguments above, the following attributes are exported:
39+
40+
* `id` - The resource ID in UUID format.

huaweicloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,6 +3080,7 @@ func Provider() *schema.Provider {
30803080
"huaweicloud_hss_container_kubernetes_cluster_daemonset": hss.ResourceContainerKubernetesClusterDaemonset(),
30813081
"huaweicloud_hss_container_kubernetes_cluster_protection_enable": hss.ResourceContainerKubernetesClusterProtectionEnable(),
30823082
"huaweicloud_hss_container_network_policy_sync": hss.ResourceContainerNetworkPolicySync(),
3083+
"huaweicloud_hss_container_network_cluster_sync": hss.ResourceContainerNetworkClusterSync(),
30833084
"huaweicloud_hss_cluster_protect_switch_mode": hss.ResourceClusterProtectSwitchMode(),
30843085
"huaweicloud_hss_cicd_configuration": hss.ResourceCiCdConfiguration(),
30853086
"huaweicloud_hss_honeypot_port_policy": hss.ResourceHoneypotPortPolicy(),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package hss
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
9+
)
10+
11+
func TestAccContainerNetworkClusterSync_basic(t *testing.T) {
12+
// lintignore:AT001
13+
resource.ParallelTest(t, resource.TestCase{
14+
PreCheck: func() {
15+
acceptance.TestAccPreCheck(t)
16+
},
17+
ProviderFactories: acceptance.TestAccProviderFactories,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testContainerNetworkClusterSync_basic(),
21+
},
22+
},
23+
})
24+
}
25+
26+
func testContainerNetworkClusterSync_basic() string {
27+
return `
28+
resource "huaweicloud_hss_container_network_cluster_sync" "test" {
29+
enterprise_project_id = "0"
30+
}
31+
`
32+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package hss
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/hashicorp/go-uuid"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12+
13+
"github.com/chnsz/golangsdk"
14+
15+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
16+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
17+
)
18+
19+
var containerNetworkClusterSyncNonUpdatableParams = []string{
20+
"enterprise_project_id",
21+
}
22+
23+
// @API HSS GET /v5/{project_id}/container-network/cluster/sync
24+
func ResourceContainerNetworkClusterSync() *schema.Resource {
25+
return &schema.Resource{
26+
CreateContext: resourceContainerNetworkClusterSyncCreate,
27+
ReadContext: resourceContainerNetworkClusterSyncRead,
28+
UpdateContext: resourceContainerNetworkClusterSyncUpdate,
29+
DeleteContext: resourceContainerNetworkClusterSyncDelete,
30+
31+
CustomizeDiff: config.FlexibleForceNew(containerNetworkClusterSyncNonUpdatableParams),
32+
33+
Schema: map[string]*schema.Schema{
34+
"region": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
Computed: true,
38+
ForceNew: true,
39+
},
40+
"enterprise_project_id": {
41+
Type: schema.TypeString,
42+
Optional: true,
43+
},
44+
"enable_force_new": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
48+
Description: utils.SchemaDesc("", utils.SchemaDescInput{Internal: true}),
49+
},
50+
},
51+
}
52+
}
53+
54+
func buildContainerNetworkClusterSyncQueryParams(epsId string) string {
55+
if epsId != "" {
56+
return fmt.Sprintf("?enterprise_project_id=%v", epsId)
57+
}
58+
59+
return ""
60+
}
61+
62+
func resourceContainerNetworkClusterSyncCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
63+
var (
64+
cfg = meta.(*config.Config)
65+
region = cfg.GetRegion(d)
66+
product = "hss"
67+
epsId = cfg.GetEnterpriseProjectID(d)
68+
)
69+
70+
client, err := cfg.NewServiceClient(product, region)
71+
if err != nil {
72+
return diag.Errorf("error creating HSS client: %s", err)
73+
}
74+
75+
requestPath := client.Endpoint + "v5/{project_id}/container-network/cluster/sync"
76+
requestPath = strings.ReplaceAll(requestPath, "{project_id}", client.ProjectID)
77+
requestPath += buildContainerNetworkClusterSyncQueryParams(epsId)
78+
requestOpt := golangsdk.RequestOpts{
79+
KeepResponseBody: true,
80+
}
81+
82+
_, err = client.Request("GET", requestPath, &requestOpt)
83+
if err != nil {
84+
return diag.Errorf("error syncing HSS container network cluster: %s", err)
85+
}
86+
87+
generateUUID, err := uuid.GenerateUUID()
88+
if err != nil {
89+
return diag.Errorf("unable to generate ID: %s", err)
90+
}
91+
92+
d.SetId(generateUUID)
93+
94+
return resourceContainerNetworkClusterSyncRead(ctx, d, meta)
95+
}
96+
97+
func resourceContainerNetworkClusterSyncRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
98+
// No processing is performed in the 'Read()' method because the resource is a one-time action resource.
99+
return nil
100+
}
101+
102+
func resourceContainerNetworkClusterSyncUpdate(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
103+
// No processing is performed in the 'Update()' method because the resource is a one-time action resource.
104+
return nil
105+
}
106+
107+
func resourceContainerNetworkClusterSyncDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
108+
errorMsg := `This resource is a one-time action resource used to sync HSS container network cluster. Deleting this
109+
resource will not clear the corresponding request record, but will only remove the resource information from the
110+
tf state file.`
111+
return diag.Diagnostics{
112+
diag.Diagnostic{
113+
Severity: diag.Warning,
114+
Summary: errorMsg,
115+
},
116+
}
117+
}

0 commit comments

Comments
 (0)