Skip to content

Commit 3cc9017

Browse files
committed
feat(servicestage): add new resource supports configuration file
1 parent f0b8f06 commit 3cc9017

File tree

4 files changed

+548
-0
lines changed

4 files changed

+548
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
subcategory: "ServiceStage"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_servicestagev3_configuration"
5+
description: |-
6+
Manages a configuration file resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_servicestagev3_configuration
10+
11+
Manages a configuration file resource within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
variable "config_group_id" {}
17+
variable "config_name" {}
18+
19+
resource "huaweicloud_servicestagev3_configuration" "test" {
20+
config_group_id = var.config_group_id
21+
name = var.config_name
22+
type = "properties"
23+
content = <<EOF
24+
spring.application.name=service
25+
cloud.servicecomb.service.name=$${spring.application.name}
26+
cloud.servicecomb.service.version=$${CAS_INSTANCE_VERSION}
27+
cloud.servicecomb.service.application=$${CAS_APPLICATION_NAME}
28+
cloud.servicecomb.discovery.address=$${PAAS_CSE_SC_ENDPOINT}
29+
cloud.servicecomb.discovery.healthCheckInterval=10
30+
cloud.servicecomb.discovery.pollInterval=15000
31+
cloud.servicecomb.discovery.waitTimeForShutDownInMillis=15000
32+
cloud.servicecomb.config.serverAddr=$${PAAS_CSE_CC_ENDPOINT}
33+
cloud.servicecomb.config.serverType=kie
34+
cloud.servicecomb.config.fileSource=governance.yaml,application.yaml
35+
EOF
36+
}
37+
```
38+
39+
## Argument Reference
40+
41+
The following arguments are supported:
42+
43+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
44+
If omitted, the provider-level region will be used. Changing this creates a new resource.
45+
46+
* `config_group_id` - (Required, String, NonUpdatable) Specifies the ID of the configuration group to which
47+
the configuration file belongs.
48+
49+
* `name` - (Required, String, NonUpdatable) Specifies the name of the configuration file.
50+
The valid length is limited from `2` to `64`, only letters, digits, hyphens (-) and underscores (_) are allowed.
51+
The name must start with a letter and end with a letter or a digit.
52+
53+
* `content` - (Required, String) Specifies the content of the configuration file.
54+
For details about the system variables that can be written into a configuration file, please refer to the [document](https://support.huaweicloud.com/intl/en-us/usermanual-servicestage/servicestage_03_0316.html#servicestage_03_0316__en-us_topic_0000001904007428_table62206277581).
55+
56+
* `type` - (Required, String) Specifies the type of the configuration file.
57+
The valid values are as follows:
58+
+ **yaml**
59+
+ **properties**
60+
61+
* `sensitive` - (Optional, Bool) Specifies whether to enable data encryption.
62+
Defaults to **false**.
63+
Only container-deployed components support data encryption. If data encryption is enabled, the configuration file is
64+
mounted using secret. If data encryption is disabled, the configuration file is mounted using ConfigMap.
65+
66+
* `description` - (Optional, String) Specifies the description of the configuration file.
67+
The maximum length is `128` characters.
68+
69+
## Attribute Reference
70+
71+
In addition to all arguments above, the following attributes are exported:
72+
73+
* `id` - The resource ID, also configuration file ID.
74+
75+
* `components` - The list of the components associated with the configuration file.
76+
The [components](#configuration_attr_components) structure is documented below.
77+
78+
* `version` - The version of the configuration file.
79+
80+
* `creator` - The creator name of the configuration file.
81+
82+
* `created_at` - The creation time of the configuration file, in RFC3339 format.
83+
84+
* `updated_at` - The latest update time of the configuration file, in RFC3339 format.
85+
86+
<a name="configuration_attr_components"></a>
87+
The `components` block supports:
88+
89+
* `environment_id` - The ID of the environment.
90+
91+
* `application_id` - The ID of the application.
92+
93+
* `component_id` - The ID of the component.
94+
95+
* `component_name` - The name of the component.
96+
97+
## Import
98+
99+
The resource can be imported using `id`, e.g.
100+
101+
```bash
102+
$ terraform import huaweicloud_servicestagev3_configuration.test <id>
103+
```

huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,7 @@ func Provider() *schema.Provider {
22662266
// v3 managements
22672267
"huaweicloud_servicestagev3_application": servicestage.ResourceV3Application(),
22682268
"huaweicloud_servicestagev3_component": servicestage.ResourceV3Component(),
2269+
"huaweicloud_servicestagev3_configuration": servicestage.ResourceV3Configuration(),
22692270
"huaweicloud_servicestagev3_environment": servicestage.ResourceV3Environment(),
22702271
"huaweicloud_servicestagev3_environment_associate": servicestage.ResourceV3EnvironmentAssociate(),
22712272

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package servicestage
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10+
11+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
12+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
13+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/servicestage"
14+
)
15+
16+
func getV3Configuration(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
17+
client, err := conf.NewServiceClient("servicestage", acceptance.HW_REGION_NAME)
18+
if err != nil {
19+
return nil, fmt.Errorf("error creating ServiceStage client: %s", err)
20+
}
21+
return servicestage.GetV3ConfigurationFile(client, state.Primary.ID)
22+
}
23+
24+
func TestAccV3Configuration_basic(t *testing.T) {
25+
var (
26+
configuration interface{}
27+
resourceName = "huaweicloud_servicestagev3_configuration.test"
28+
rc = acceptance.InitResourceCheck(resourceName, &configuration, getV3Configuration)
29+
30+
name = acceptance.RandomAccResourceName()
31+
)
32+
33+
resource.ParallelTest(t, resource.TestCase{
34+
PreCheck: func() { acceptance.TestAccPreCheck(t) },
35+
ProviderFactories: acceptance.TestAccProviderFactories,
36+
CheckDestroy: rc.CheckResourceDestroy(),
37+
Steps: []resource.TestStep{
38+
{
39+
Config: testAccV3Configuration_basic_step1(name),
40+
Check: resource.ComposeTestCheckFunc(
41+
rc.CheckResourceExists(),
42+
resource.TestCheckResourceAttrPair(resourceName, "config_group_id", "huaweicloud_servicestagev3_configuration_group.test", "id"),
43+
resource.TestCheckResourceAttr(resourceName, "name", name),
44+
resource.TestCheckResourceAttr(resourceName, "type", "properties"),
45+
resource.TestCheckResourceAttr(resourceName, "content", "testkey = testvalue"),
46+
resource.TestCheckResourceAttr(resourceName, "sensitive", "true"),
47+
resource.TestCheckResourceAttr(resourceName, "description", "Created by TF script"),
48+
resource.TestCheckResourceAttr(resourceName, "components.#", "0"),
49+
resource.TestCheckResourceAttrSet(resourceName, "version"),
50+
resource.TestCheckResourceAttrSet(resourceName, "creator"),
51+
resource.TestMatchResourceAttr(resourceName, "created_at",
52+
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
53+
resource.TestMatchResourceAttr(resourceName, "created_at",
54+
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
55+
),
56+
},
57+
{
58+
Config: testAccV3Configuration_basic_step2(name),
59+
Check: resource.ComposeTestCheckFunc(
60+
rc.CheckResourceExists(),
61+
resource.TestCheckResourceAttr(resourceName, "type", "yaml"),
62+
resource.TestCheckResourceAttr(resourceName, "sensitive", "false"),
63+
resource.TestCheckResourceAttr(resourceName, "description", ""),
64+
),
65+
},
66+
{
67+
ResourceName: resourceName,
68+
ImportState: true,
69+
ImportStateVerify: true,
70+
},
71+
},
72+
})
73+
}
74+
75+
func testAccV3Configuration_basic_step1(name string) string {
76+
return fmt.Sprintf(`
77+
%[1]s
78+
79+
resource "huaweicloud_servicestagev3_configuration" "test" {
80+
config_group_id = huaweicloud_servicestagev3_configuration_group.test.id
81+
name = "%[2]s"
82+
type = "properties"
83+
content = "testkey = testvalue"
84+
sensitive = true
85+
description = "Created by TF script"
86+
}
87+
`, testAccV3ConfigurationGroup_basic(name), name)
88+
}
89+
90+
func testAccV3Configuration_basic_step2(name string) string {
91+
return fmt.Sprintf(`
92+
%[1]s
93+
94+
resource "huaweicloud_servicestagev3_configuration" "test" {
95+
config_group_id = huaweicloud_servicestagev3_configuration_group.test.id
96+
name = "%[2]s"
97+
type = "yaml"
98+
content = <<EOF
99+
spring:
100+
application:
101+
name: "service"
102+
cloud:
103+
servicecomb:
104+
service:
105+
name: service
106+
version: $${CAS_INSTANCE_VERSION}
107+
application: $${CAS_APPLICATION_NAME}
108+
discovery:
109+
address: $${PAAS_CSE_SC_ENDPOINT}
110+
healthCheckInterval: 10
111+
pollInterval: 15000
112+
waitTimeForShutDownInMillis: 15000
113+
config:
114+
serverAddr: $${PAAS_CSE_CC_ENDPOINT}
115+
serverType: kie
116+
fileSource: governance.yaml,application.yaml
117+
EOF
118+
}
119+
`, testAccV3ConfigurationGroup_basic(name), name)
120+
}

0 commit comments

Comments
 (0)