Skip to content

Commit 21ed284

Browse files
committed
feat(cci): add resource CCI v2 namespace
1 parent c454f7c commit 21ed284

File tree

4 files changed

+434
-0
lines changed

4 files changed

+434
-0
lines changed

Diff for: docs/incubating/cciv2_namespace.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
subcategory: "Cloud Container Instance (CCI)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_cciv2_namespace"
5+
description: |-
6+
Manages a CCI v2 namespace resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_cciv2_namespace
10+
11+
Manages a CCI v2 namespace resource within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
variable "name" {}
17+
18+
resource "huaweicloud_cciv2_namespace" "test" {
19+
name = var.name
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
28+
If omitted, the provider-level region will be used.
29+
Changing this creates a new resource.
30+
31+
* `name` - (Required, String, NonUpdatable) Specifies the unique name of the namespace.
32+
33+
## Attribute Reference
34+
35+
In addition to all arguments above, the following attributes are exported:
36+
37+
* `id` - The resource ID. The value is also the name of the namespace.
38+
39+
* `api_version` - The API version of the namespace.
40+
41+
* `kind` - The kind of the namespace.
42+
43+
* `annotations` - The annotations of the namespace.
44+
45+
* `labels` - The labels of the namespace.
46+
47+
* `creation_timestamp` - The creation timestamp of the namespace.
48+
49+
* `resource_version` - The resource version of the namespace.
50+
51+
* `uid` - The uid of the namespace.
52+
53+
* `finalizers` - The finalizers of the namespace.
54+
55+
* `status` - The status of the namespace.
56+
57+
## Timeouts
58+
59+
This resource provides the following timeouts configuration options:
60+
61+
* `create` - Default is 5 minutes.
62+
* `delete` - Default is 3 minutes.
63+
64+
## Import
65+
66+
The CCI v2 namespace can be imported using `name`, e.g.
67+
68+
```bash
69+
$ terraform import huaweicloud_cciv2_namespace.test <name>
70+
```

Diff for: huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ func Provider() *schema.Provider {
15491549
"huaweicloud_cci_namespace": cci.ResourceCciNamespace(),
15501550
"huaweicloud_cci_network": cci.ResourceCciNetworkV1(),
15511551
"huaweicloud_cci_pvc": cci.ResourcePersistentVolumeClaimV1(),
1552+
"huaweicloud_cciv2_namespace": cci.ResourceNamespace(),
15521553

15531554
"huaweicloud_ccm_certificate": ccm.ResourceCCMCertificate(),
15541555
"huaweicloud_ccm_certificate_apply": ccm.ResourceCertificateApply(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cci
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9+
10+
"github.com/chnsz/golangsdk/openstack/cci/v1/namespaces"
11+
12+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
13+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
14+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cci"
15+
)
16+
17+
func getV2NamespaceResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
18+
c, err := conf.CciV2Client(acceptance.HW_REGION_NAME)
19+
if err != nil {
20+
return nil, fmt.Errorf("error creating HuaweiCloud CCI v2 client: %s", err)
21+
}
22+
return cci.GetNamespaceDetail(c, state.Primary.ID)
23+
}
24+
25+
func TestAccV2Namespace_basic(t *testing.T) {
26+
var ns namespaces.Namespace
27+
rName := acceptance.RandomAccResourceNameWithDash()
28+
resourceName := "huaweicloud_cciv2_namespace.test"
29+
30+
rc := acceptance.InitResourceCheck(
31+
resourceName,
32+
&ns,
33+
getV2NamespaceResourceFunc,
34+
)
35+
36+
resource.ParallelTest(t, resource.TestCase{
37+
PreCheck: func() {
38+
acceptance.TestAccPreCheck(t)
39+
},
40+
ProviderFactories: acceptance.TestAccProviderFactories,
41+
CheckDestroy: rc.CheckResourceDestroy(),
42+
Steps: []resource.TestStep{
43+
{
44+
Config: testAccV2Namespace_basic(rName),
45+
Check: resource.ComposeTestCheckFunc(
46+
rc.CheckResourceExists(),
47+
resource.TestCheckResourceAttr(resourceName, "name", rName),
48+
resource.TestCheckResourceAttr(resourceName, "api_version", "cci/v2"),
49+
resource.TestCheckResourceAttr(resourceName, "kind", "Namespace"),
50+
resource.TestCheckResourceAttr(resourceName, "finalizers.0", "kubernetes"),
51+
resource.TestCheckResourceAttr(resourceName, "status", "Active"),
52+
resource.TestCheckResourceAttrSet(resourceName, "annotations.%"),
53+
resource.TestCheckResourceAttrSet(resourceName, "labels.%"),
54+
resource.TestCheckResourceAttrSet(resourceName, "creation_timestamp"),
55+
resource.TestCheckResourceAttrSet(resourceName, "resource_version"),
56+
),
57+
},
58+
{
59+
ResourceName: resourceName,
60+
ImportState: true,
61+
ImportStateVerify: true,
62+
},
63+
},
64+
})
65+
}
66+
67+
func testAccV2Namespace_basic(rName string) string {
68+
return fmt.Sprintf(`
69+
resource "huaweicloud_cciv2_namespace" "test" {
70+
name = "%s"
71+
}
72+
`, rName)
73+
}

0 commit comments

Comments
 (0)