-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat.] New HSS host group resource opentelekomcloud_hss_host_group_v5
#2718
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
subcategory: "Host Security Service (HSS)" | ||
layout: "opentelekomcloud" | ||
page_title: "OpenTelekomCloud: opentelekomcloud_hss_host_group_v5" | ||
sidebar_current: "docs-opentelekomcloud-resource-hss-host-group-v5" | ||
description: |- | ||
Manages an HSS host group Service resource within OpenTelekomCloud. | ||
--- | ||
|
||
# opentelekomcloud_hss_host_group_v5 | ||
|
||
Manages an HSS host group resource within OpenTelekomCloud. | ||
|
||
## Example Usage | ||
|
||
### Create an HSS host group and bind ECS instances | ||
|
||
```hcl | ||
variable "host_group_name" {} | ||
variable "host_ids" { | ||
type = list(string) | ||
} | ||
|
||
resource "opentelekomcloud_hss_host_group_v5" "test" { | ||
name = var.host_group_name | ||
host_ids = var.host_ids | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required, String) Specifies the name of the host group. | ||
The valid length is limited from `1` to `64`, only Chinese characters, English letters, digits, hyphens (-), | ||
underscores (_), dots (.), pluses (+) and asterisks (*) are allowed. | ||
The Chinese characters must be in `UTF-8` or `Unicode` format. | ||
|
||
* `host_ids` - (Required, List) Specifies the list of host IDs. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID in UUID format. | ||
|
||
* `host_num` - The total host number. | ||
|
||
* `region` - The region where the host group is located. | ||
|
||
* `risk_host_num` - The number of hosts at risk. | ||
|
||
* `unprotect_host_num` - The number of unprotect hosts. | ||
|
||
* `unprotect_host_ids` - The ID list of the unprotect hosts. | ||
|
||
## Timeouts | ||
|
||
This resource provides the following timeouts configuration options: | ||
|
||
* `create` - Default is 30 minutes. | ||
* `update` - Default is 30 minutes. | ||
|
||
## Import | ||
|
||
The host group resource can be imported using `id`, e.g. | ||
|
||
```bash | ||
$ terraform import opentelekomcloud_hss_host_group_v5.group <id> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
opentelekomcloud/acceptance/hss/resource_opentelekomcloud_hss_host_group_v5_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package hss | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
group "github.com/opentelekomcloud/gophertelekomcloud/openstack/hss/v5/host" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/hss" | ||
) | ||
|
||
func getHostGroupFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := conf.HssV5Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating HSS v5 client: %s", err) | ||
} | ||
return hss.QueryHostGroupById(client, state.Primary.ID) | ||
} | ||
|
||
func TestAccHostGroup_basic(t *testing.T) { | ||
var ( | ||
gr *group.HostGroupResp | ||
|
||
name = fmt.Sprintf("hss-acc-api%s", acctest.RandString(5)) | ||
rName = "opentelekomcloud_hss_host_group_v5.group" | ||
) | ||
|
||
rc := common.InitResourceCheck( | ||
rName, | ||
&gr, | ||
getHostGroupFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
common.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccHostGroup_basic(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "name", name), | ||
resource.TestCheckResourceAttr(rName, "host_ids.#", "1"), | ||
resource.TestCheckResourceAttrSet(rName, "host_num"), | ||
), | ||
}, | ||
{ | ||
Config: testAccHostGroup_update(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "name", name+"-update"), | ||
resource.TestCheckResourceAttr(rName, "host_ids.#", "2"), | ||
resource.TestCheckResourceAttrSet(rName, "host_num"), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
// The field `unprotect_host_ids` will be filled in during the creation and editing operations. | ||
// We only need to add ignore to the test case and do not need to make special instructions in the document. | ||
ImportStateVerifyIgnore: []string{ | ||
"unprotect_host_ids", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccHostGroup_base(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "opentelekomcloud_compute_instance_v2" "instance" { | ||
count = 2 | ||
|
||
name = "%s" | ||
description = "my_desc" | ||
availability_zone = "%s" | ||
|
||
image_name = "Standard_Debian_11_latest" | ||
flavor_id = "s3.large.2" | ||
|
||
metadata = { | ||
foo = "bar" | ||
} | ||
network { | ||
uuid = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id | ||
} | ||
|
||
tags = { | ||
muh = "value-create" | ||
kuh = "value-create" | ||
emp = "" | ||
} | ||
|
||
stop_before_destroy = true | ||
} | ||
`, common.DataSourceSubnet, name, env.OS_AVAILABILITY_ZONE) | ||
} | ||
|
||
func testAccHostGroup_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "opentelekomcloud_hss_host_group_v5" "group" { | ||
name = "%[2]s" | ||
host_ids = slice(opentelekomcloud_compute_instance_v2.instance[*].id, 0, 1) | ||
} | ||
`, testAccHostGroup_base(name), name) | ||
} | ||
|
||
func testAccHostGroup_update(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "opentelekomcloud_hss_host_group_v5" "group" { | ||
name = "%[2]s-update" | ||
host_ids = opentelekomcloud_compute_instance_v2.instance[*].id | ||
} | ||
`, testAccHostGroup_base(name), name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package hss | ||
|
||
const ( | ||
errCreationV5Client = "error creating OpenTelekomCloud HSS v5 client: %w" | ||
hssClientV5 = "hss-v5-client" | ||
) | ||
|
||
type ProtectStatus string | ||
|
||
const ( | ||
ProtectStatusClosed ProtectStatus = "closed" | ||
ProtectStatusOpened ProtectStatus = "opened" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why v5 if this is a new resource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in documentation it v5 and for future reasons we trying to keep versions: https://docs.otc.t-systems.com/host-security-service/api-ref/api_description/server_management/querying_ecss.html#listhoststatus