Skip to content

Commit 694c89b

Browse files
committed
feat(cci): add resource CCI v2 network
1 parent 91cd54c commit 694c89b

File tree

4 files changed

+905
-0
lines changed

4 files changed

+905
-0
lines changed

docs/incubating/cciv2_network.md

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
subcategory: "Cloud Container Instance (CCI)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_cciv2_network"
5+
description: |-
6+
Manages a CCI Network resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_cciv2_network
10+
11+
Manages a CCI Network resource within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
variable "namespace" {}
17+
variable "name" {}
18+
variable "project_id" {}
19+
variable "domain_id" {}
20+
variable "subnet_id" {}
21+
variable "security_group_ids" {}
22+
23+
resource "huaweicloud_cciv2_network" "test" {
24+
namesapce = var.namespace
25+
name = var.name
26+
27+
annotations = {
28+
"yangtse.io/project-id" = var.project_id,
29+
"yangtse.io/domain-id" = var.domain_id,
30+
"yangtse.io/warm-pool-size" = "10",
31+
"yangtse.io/warm-pool-recycle-interval" = "2",
32+
}
33+
34+
subnets {
35+
subnet_id = var.subnet_id
36+
}
37+
38+
security_group_ids = var.security_group_ids
39+
}
40+
```
41+
42+
## Argument Reference
43+
44+
The following arguments are supported:
45+
46+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
47+
If omitted, the provider-level region will be used.
48+
Changing this creates a new resource.
49+
50+
* `name` - (Required, String, NonUpdatable) Specifies the name of the CCI network.
51+
52+
* `namespace` - (Required, String, NonUpdatable) Specifies the namespace.
53+
54+
* `annotations` - (Optional, Map) Specifies the annotations of the CCI network.
55+
56+
* `ip_families` - (Optional, List, NonUpdatable) Specifies the IP families of the CCI network.
57+
When IPV6 is enabled, the value can be **["IPv4", "IPv6"]**.
58+
59+
* `security_group_ids` - (Optional, List) Specifies the security group IDs of the CCI network.
60+
61+
* `subnets` - (Optional, List, NonUpdatable) Specifies the subnets of the CCI network.
62+
The [subnets](#block_subnets) structure is documented below.
63+
64+
<a name="block_subnets"></a>
65+
The `subnets` block supports:
66+
67+
* `subnet_id` - (Optional, String, NonUpdatable) Specifies the subnet ID of the CCI network.
68+
69+
## Attribute Reference
70+
71+
In addition to all arguments above, the following attributes are exported:
72+
73+
* `id` - The resource ID.
74+
75+
* `api_version` - The API version of the CCI network.
76+
77+
* `kind` - The kind of the CCI network.
78+
79+
* `creation_timestamp` - The creation timestamp of the namespace.
80+
81+
* `finalizers` - The finalizers of the namespace.
82+
83+
* `resource_version` - The resource version of the namespace.
84+
85+
* `status` - The status of the namespace.
86+
The [status](#attrblock_status) structure is documented below.
87+
88+
* `uid` - The uid of the namespace.
89+
90+
<a name="attrblock_status"></a>
91+
The `status` block supports:
92+
93+
* `conditions` - The conditions of the CCI network.
94+
The [conditions](#attrblock_status_conditions) structure is documented below.
95+
96+
* `status` - The status of the CCI network.
97+
98+
* `subnet_attrs` - The subnet attributes of the CCI network.
99+
The [subnet_attrs](#attrblock_status_subnet_attrs) structure is documented below.
100+
101+
<a name="attrblock_status_conditions"></a>
102+
The `conditions` block supports:
103+
104+
* `last_transition_time` - The last transition time of the CCI network conditions.
105+
106+
* `message` - The message of the CCI network conditions.
107+
108+
* `reason` - The reason of the CCI network conditions.
109+
110+
* `status` - The status of the CCI network conditions.
111+
112+
* `type` - The type of the CCI network conditions.
113+
114+
<a name="attrblock_status_subnet_attrs"></a>
115+
The `subnet_attrs` block supports:
116+
117+
* `network_id` - The ID of the CCI network.
118+
119+
* `subnet_v4_id` - The subnet IPv4 ID of the CCI network.
120+
121+
* `subnet_v6_id` - The subnet IPv6 ID of the CCI network.
122+
123+
## Timeouts
124+
125+
This resource provides the following timeouts configuration options:
126+
127+
* `create` - Default is 10 minutes.
128+
* `delete` - Default is 10 minutes.
129+
130+
## Import
131+
132+
The CCI Network can be imported using `namespace` and `name`, separated by a slash, e.g.
133+
134+
```bash
135+
$ terraform import huaweicloud_cciv2_network.test <namespace>/<name>
136+
```

huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,7 @@ func Provider() *schema.Provider {
15871587
"huaweicloud_cci_network": cci.ResourceCciNetworkV1(),
15881588
"huaweicloud_cci_pvc": cci.ResourcePersistentVolumeClaimV1(),
15891589
"huaweicloud_cciv2_namespace": cci.ResourceNamespace(),
1590+
"huaweicloud_cciv2_network": cci.ResourceV2Network(),
15901591

15911592
"huaweicloud_ccm_certificate": ccm.ResourceCCMCertificate(),
15921593
"huaweicloud_ccm_certificate_apply": ccm.ResourceCertificateApply(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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/networks"
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/acceptance/common"
15+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cci"
16+
)
17+
18+
func getV2NetworkResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
19+
client, err := conf.NewServiceClient("cci", acceptance.HW_REGION_NAME)
20+
if err != nil {
21+
return nil, fmt.Errorf("error creating CCI Yangtse v2 client: %s", err)
22+
}
23+
return cci.GetNetwork(client, state.Primary.Attributes["namespace"], state.Primary.Attributes["name"])
24+
}
25+
26+
func TestAccV2Network_basic(t *testing.T) {
27+
var network networks.Network
28+
rName := acceptance.RandomAccResourceNameWithDash()
29+
resourceName := "huaweicloud_cciv2_network.test"
30+
31+
rc := acceptance.InitResourceCheck(
32+
resourceName,
33+
&network,
34+
getV2NetworkResourceFunc,
35+
)
36+
37+
resource.ParallelTest(t, resource.TestCase{
38+
PreCheck: func() { acceptance.TestAccPreCheck(t) },
39+
ProviderFactories: acceptance.TestAccProviderFactories,
40+
CheckDestroy: rc.CheckResourceDestroy(),
41+
Steps: []resource.TestStep{
42+
{
43+
Config: testAccV2Network_basic(rName),
44+
Check: resource.ComposeTestCheckFunc(
45+
rc.CheckResourceExists(),
46+
resource.TestCheckResourceAttr(resourceName, "namespace", rName),
47+
resource.TestCheckResourceAttr(resourceName, "name", rName),
48+
resource.TestCheckOutput("is_warm_pool_size_pass", "true"),
49+
resource.TestCheckOutput("is_warm_pool_recycle_interval_pass", "true"),
50+
resource.TestCheckResourceAttrPair(resourceName, "subnets.0.subnet_id",
51+
"huaweicloud_vpc_subnet.test", "subnet_id"),
52+
resource.TestCheckResourceAttrPair(resourceName, "security_group_ids.0",
53+
"huaweicloud_networking_secgroup.test", "id"),
54+
resource.TestCheckResourceAttrSet(resourceName, "api_version"),
55+
resource.TestCheckResourceAttrSet(resourceName, "kind"),
56+
resource.TestCheckResourceAttrSet(resourceName, "creation_timestamp"),
57+
resource.TestCheckResourceAttrSet(resourceName, "finalizers.#"),
58+
resource.TestCheckResourceAttrSet(resourceName, "resource_version"),
59+
resource.TestCheckResourceAttrSet(resourceName, "uid"),
60+
resource.TestCheckResourceAttrSet(resourceName, "status.0.status"),
61+
resource.TestCheckResourceAttrSet(resourceName, "status.0.conditions.#"),
62+
resource.TestCheckResourceAttrSet(resourceName, "status.0.subnet_attrs.#"),
63+
resource.TestCheckResourceAttrPair(resourceName, "status.0.subnet_attrs.0.network_id",
64+
"huaweicloud_vpc_subnet.test", "id"),
65+
resource.TestCheckResourceAttrPair(resourceName, "status.0.subnet_attrs.0.subnet_v4_id",
66+
"huaweicloud_vpc_subnet.test", "subnet_id"),
67+
),
68+
},
69+
{
70+
Config: testAccV2Network_update(rName),
71+
Check: resource.ComposeTestCheckFunc(
72+
rc.CheckResourceExists(),
73+
resource.TestCheckOutput("is_warm_pool_size_pass", "true"),
74+
resource.TestCheckOutput("is_warm_pool_recycle_interval_pass", "true"),
75+
resource.TestCheckResourceAttrPair(resourceName, "security_group_ids.0",
76+
"huaweicloud_networking_secgroup.test1", "id"),
77+
),
78+
},
79+
{
80+
ResourceName: resourceName,
81+
ImportState: true,
82+
ImportStateVerify: true,
83+
ImportStateIdFunc: testAccV2NetworkImportStateFunc(resourceName),
84+
},
85+
},
86+
})
87+
}
88+
89+
func testAccV2NetworkImportStateFunc(name string) resource.ImportStateIdFunc {
90+
return func(s *terraform.State) (string, error) {
91+
rs, ok := s.RootModule().Resources[name]
92+
if !ok {
93+
return "", fmt.Errorf("Resource (%s) not found: %s", name, rs)
94+
}
95+
if rs.Primary.ID == "" || rs.Primary.Attributes["namespace"] == "" || rs.Primary.Attributes["name"] == "" {
96+
return "", fmt.Errorf("the namespace (%s) or name(%s) or ID (%s) is nil",
97+
rs.Primary.Attributes["namespace"], rs.Primary.Attributes["name"], rs.Primary.ID)
98+
}
99+
return fmt.Sprintf("%s/%s", rs.Primary.Attributes["namespace"], rs.Primary.Attributes["name"]), nil
100+
}
101+
}
102+
103+
func testAccV2Network_basic(rName string) string {
104+
return fmt.Sprintf(`
105+
%[1]s
106+
107+
%[2]s
108+
109+
resource "huaweicloud_cciv2_network" "test" {
110+
namespace = huaweicloud_cciv2_namespace.test.name
111+
name = "%[3]s"
112+
113+
annotations = {
114+
"yangtse.io/project-id" = huaweicloud_cciv2_namespace.test.annotations["tenant.kubernetes.io/project-id"],
115+
"yangtse.io/domain-id" = huaweicloud_cciv2_namespace.test.annotations["tenant.kubernetes.io/domain-id"],
116+
"yangtse.io/warm-pool-size" = "10",
117+
"yangtse.io/warm-pool-recycle-interval" = "2",
118+
}
119+
120+
subnets {
121+
subnet_id = huaweicloud_vpc_subnet.test.subnet_id
122+
}
123+
124+
security_group_ids = [huaweicloud_networking_secgroup.test.id]
125+
}
126+
127+
output "is_warm_pool_size_pass" {
128+
value = huaweicloud_cciv2_network.test.annotations["yangtse.io/warm-pool-size"] == "10"
129+
}
130+
131+
output "is_warm_pool_recycle_interval_pass" {
132+
value = huaweicloud_cciv2_network.test.annotations["yangtse.io/warm-pool-recycle-interval"] == "2"
133+
}
134+
`, common.TestBaseNetwork(rName), testAccV2Namespace_basic(rName), rName)
135+
}
136+
137+
func testAccV2Network_update(rName string) string {
138+
return fmt.Sprintf(`
139+
%[1]s
140+
141+
%[2]s
142+
143+
resource "huaweicloud_networking_secgroup" "test1" {
144+
name = "%[3]s_update"
145+
delete_default_rules = true
146+
}
147+
148+
resource "huaweicloud_cciv2_network" "test" {
149+
namespace = huaweicloud_cciv2_namespace.test.name
150+
name = "%[3]s"
151+
152+
annotations = {
153+
"yangtse.io/project-id" = huaweicloud_cciv2_namespace.test.annotations["tenant.kubernetes.io/project-id"],
154+
"yangtse.io/domain-id" = huaweicloud_cciv2_namespace.test.annotations["tenant.kubernetes.io/domain-id"],
155+
"yangtse.io/warm-pool-size" = "8",
156+
"yangtse.io/warm-pool-recycle-interval" = "3",
157+
}
158+
159+
subnets {
160+
subnet_id = huaweicloud_vpc_subnet.test.subnet_id
161+
}
162+
163+
security_group_ids = [huaweicloud_networking_secgroup.test1.id]
164+
}
165+
166+
output "is_warm_pool_size_pass" {
167+
value = huaweicloud_cciv2_network.test.annotations["yangtse.io/warm-pool-size"] == "8"
168+
}
169+
170+
output "is_warm_pool_recycle_interval_pass" {
171+
value = huaweicloud_cciv2_network.test.annotations["yangtse.io/warm-pool-recycle-interval"] == "3"
172+
}
173+
`, common.TestBaseNetwork(rName), testAccV2Namespace_basic(rName), rName)
174+
}

0 commit comments

Comments
 (0)