Skip to content

Commit fcd19df

Browse files
committed
feat(CodeArts/Pipeline): support resource template
1 parent 683ff47 commit fcd19df

File tree

6 files changed

+545
-2
lines changed

6 files changed

+545
-2
lines changed

docs/resources/codearts_build_task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ The `steps` block supports:
141141

142142
* `enable` - (Optional, Bool) Specifies whether to enable the step. Defaults to **false**.
143143

144-
* `properties` - (Optional, Map) Specifies the build step properties.
144+
* `properties` - (Optional, Map) Specifies the build step properties. Value is JSON format string.
145145

146146
* `version` - (Optional, String) Specifies the build step version.
147147

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
subcategory: "CodeArts Build"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_codearts_build_template"
5+
description: |-
6+
Manages a CodeArts Build template resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_codearts_build_template
10+
11+
Manages a CodeArts Build template resource within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
resource "huaweicloud_codearts_build_template" "test" {
17+
name = "test-api"
18+
description = "demo"
19+
20+
steps {
21+
enable = true
22+
module_id = "devcloud2018.codeci_action_20057.action"
23+
name = "update OBS"
24+
properties = {
25+
objectKey = jsonencode("./")
26+
backetName = jsonencode("test")
27+
uploadDirectory = jsonencode(true)
28+
artifactSourcePath = jsonencode("bin/*")
29+
authorizationUser = jsonencode({
30+
"displayName": "current user",
31+
"value": "build"
32+
})
33+
obsHeaders = jsonencode([
34+
{
35+
"headerKey": "test",
36+
"headerValue": "test"
37+
}
38+
])
39+
}
40+
}
41+
}
42+
```
43+
44+
## Argument Reference
45+
46+
The following arguments are supported:
47+
48+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
49+
If omitted, the provider-level region will be used.
50+
Changing this creates a new resource.
51+
52+
* `name` - (Required, String) Specifies the name of the build template.
53+
54+
* `steps` - (Required, List) Specifies the build execution steps.
55+
The [steps](#block--steps) structure is documented below.
56+
57+
* `description` - (Optional, String) Specifies the template description.
58+
59+
* `parameters` - (Optional, List) Specifies the build execution parameter list.
60+
The [parameters](#block--parameters) structure is documented below.
61+
62+
* `tool_type` - (Optional, String) Specifies the tool type.
63+
64+
<a name="block--steps"></a>
65+
The `steps` block supports:
66+
67+
* `module_id` - (Required, String) Specifies the build step module ID.
68+
69+
* `name` - (Required, String) Specifies the build step name.
70+
71+
* `enable` - (Optional, Bool) Specifies whether to enable the step. Defaults to **false**.
72+
73+
* `properties` - (Optional, Map) Specifies the build step properties. Value is JSON format string.
74+
75+
* `version` - (Optional, String) Specifies the build step version.
76+
77+
<a name="block--parameters"></a>
78+
The `parameters` block supports:
79+
80+
* `name` - (Optional, String) Specifies the parameter definition name.
81+
82+
* `params` - (Optional, List) Specifies the build execution sub-parameters.
83+
The [params](#block--parameters--params) structure is documented below.
84+
85+
<a name="block--parameters--params"></a>
86+
The `params` block supports:
87+
88+
* `name` - (Optional, String) Specifies the parameter field name.
89+
90+
* `value` - (Optional, String) Specifies the parameter field value.
91+
92+
* `limits` - (Optional, List) Specifies the enumeration parameter restrictions.
93+
The [limits](#block--parameters--params--limits) structure is documented below.
94+
95+
<a name="block--parameters--params--limits"></a>
96+
The `limits` block supports:
97+
98+
* `disable` - (Optional, String) Specifies whether it is effective.
99+
100+
* `display_name` - (Optional, String) Specifies the displayed name of the parameter.
101+
102+
* `name` - (Optional, String) Specifies the parameter name.
103+
104+
## Attribute Reference
105+
106+
In addition to all arguments above, the following attributes are exported:
107+
108+
* `id` - The resource ID.
109+
110+
* `create_time` - Indicates the template creation time.
111+
112+
* `favorite` - Indicates whether the template is favorite.
113+
114+
* `nick_name` - Indicates the nick name.
115+
116+
* `public` - Indicates whether the template is public.
117+
118+
* `scope` - Indicates the scope.
119+
120+
* `steps` - Specifies the build execution steps.
121+
The [steps](#attrblock--steps) structure is documented below.
122+
123+
* `template_id` - Indicates ID in database.
124+
125+
* `type` - Indicates the template type.
126+
127+
* `weight` - Indicates the weight of the template.
128+
129+
<a name="attrblock--steps"></a>
130+
The `steps` block supports:
131+
132+
* `properties_all` - Specifies the build step properties.
133+
134+
## Import
135+
136+
The template can be imported using `id`, e.g.
137+
138+
```bash
139+
$ terraform import huaweicloud_codearts_build_template.test <id>
140+
```

huaweicloud/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,8 @@ func Provider() *schema.Provider {
27262726
"huaweicloud_codearts_pipeline_template": codeartspipeline.ResourceCodeArtsPipelineTemplate(),
27272727
"huaweicloud_codearts_pipeline_service_endpoint": codeartspipeline.ResourceCodeArtsPipelineServiceEndpoint(),
27282728

2729-
"huaweicloud_codearts_build_task": codeartsbuild.ResourceCodeArtsBuildTask(),
2729+
"huaweicloud_codearts_build_task": codeartsbuild.ResourceCodeArtsBuildTask(),
2730+
"huaweicloud_codearts_build_template": codeartsbuild.ResourceCodeArtsBuildTemplate(),
27302731

27312732
"huaweicloud_dsc_instance": dsc.ResourceDscInstance(),
27322733
"huaweicloud_dsc_asset_obs": dsc.ResourceAssetObs(),
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package codeartsbuild
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/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
11+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
12+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/codeartsbuild"
13+
)
14+
15+
func getBuildTemplateResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
16+
client, err := conf.NewServiceClient("codearts_build", acceptance.HW_REGION_NAME)
17+
if err != nil {
18+
return nil, fmt.Errorf("error creating CodeArts Build client: %s", err)
19+
}
20+
21+
return codeartsbuild.GetBuildTemplate(client, state.Primary.ID)
22+
}
23+
24+
func TestAccBuildTemplate_basic(t *testing.T) {
25+
var obj interface{}
26+
27+
name := acceptance.RandomAccResourceName()
28+
rName := "huaweicloud_codearts_build_template.test"
29+
30+
rc := acceptance.InitResourceCheck(
31+
rName,
32+
&obj,
33+
getBuildTemplateResourceFunc,
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: testBuildTemplate_basic(name),
45+
Check: resource.ComposeTestCheckFunc(
46+
rc.CheckResourceExists(),
47+
resource.TestCheckResourceAttr(rName, "name", name),
48+
resource.TestCheckResourceAttr(rName, "description", "demo"),
49+
resource.TestCheckResourceAttrSet(rName, "parameters.#"),
50+
resource.TestCheckResourceAttrSet(rName, "steps.#"),
51+
),
52+
},
53+
{
54+
ResourceName: rName,
55+
ImportState: true,
56+
ImportStateVerify: true,
57+
ImportStateVerifyIgnore: []string{"steps.1.properties"},
58+
},
59+
},
60+
})
61+
}
62+
63+
func testBuildTemplate_basic(name string) string {
64+
return fmt.Sprintf(`
65+
resource "huaweicloud_codearts_build_template" "test" {
66+
name = "%[1]s"
67+
description = "demo"
68+
69+
parameters {
70+
name = "hudson.model.StringParameterDefinition"
71+
72+
params {
73+
name = "name"
74+
value = "test"
75+
}
76+
params {
77+
name = "type"
78+
value = "customizeparam"
79+
}
80+
params {
81+
name = "defaultValue"
82+
value = "cs"
83+
}
84+
params {
85+
name = "staticVar"
86+
value = "false"
87+
}
88+
params {
89+
name = "sensitiveVar"
90+
value = "false"
91+
}
92+
params {
93+
name = "deletion"
94+
value = "false"
95+
}
96+
params {
97+
name = "defaults"
98+
value = "false"
99+
}
100+
}
101+
102+
steps {
103+
enable = true
104+
module_id = "devcloud2018.codeci_action_20035.action"
105+
name = "Docker Command"
106+
}
107+
108+
steps {
109+
enable = true
110+
module_id = "devcloud2018.codeci_action_20057.action"
111+
name = "update OBS"
112+
properties = {
113+
objectKey = jsonencode("./")
114+
backetName = jsonencode("test")
115+
uploadDirectory = jsonencode(true)
116+
artifactSourcePath = jsonencode("bin/*")
117+
authorizationUser = jsonencode({
118+
"displayName": "current user",
119+
"value": "build"
120+
})
121+
obsHeaders = jsonencode([
122+
{
123+
"headerKey": "1",
124+
"headerValue": "1"
125+
}
126+
])
127+
}
128+
}
129+
}
130+
`, name)
131+
}

huaweicloud/services/codeartsbuild/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
const (
1212
buildTaskNotFoundErr = "DEVCB.00031006"
13+
templateNotFoundErr = "DEV.CB.0520002"
1314
)
1415

1516
// checkResponseError use to check whether the CodeArts Build API response with OkCode but body contains error code.

0 commit comments

Comments
 (0)