Skip to content

feat(CodeArts/Pipeline): support resource template #7112

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/resources/codearts_build_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ The `steps` block supports:

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

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

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

Expand All @@ -166,13 +166,13 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `steps` - Specifies the build execution steps.
* `steps` - Indicates the build execution steps.
The [steps](#attrblock--steps) structure is documented below.

<a name="attrblock--steps"></a>
The `steps` block supports:

* `properties_all` - Specifies the build step properties.
* `properties_all` - Indicates the build step properties.

## Import

Expand Down
140 changes: 140 additions & 0 deletions docs/resources/codearts_build_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
subcategory: "CodeArts Build"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_codearts_build_template"
description: |-
Manages a CodeArts Build template resource within HuaweiCloud.
---

# huaweicloud_codearts_build_template

Manages a CodeArts Build template resource within HuaweiCloud.

## Example Usage

```hcl
resource "huaweicloud_codearts_build_template" "test" {
name = "test-api"
description = "demo"

steps {
enable = true
module_id = "devcloud2018.codeci_action_20057.action"
name = "update OBS"
properties = {
objectKey = jsonencode("./")
backetName = jsonencode("test")
uploadDirectory = jsonencode(true)
artifactSourcePath = jsonencode("bin/*")
authorizationUser = jsonencode({
"displayName": "current user",
"value": "build"
})
obsHeaders = jsonencode([
{
"headerKey": "test",
"headerValue": "test"
}
])
}
}
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used.
Changing this creates a new resource.

* `name` - (Required, String, NonUpdatable) Specifies the name of the build template.

* `steps` - (Required, List, NonUpdatable) Specifies the build execution steps.
The [steps](#block--steps) structure is documented below.

* `description` - (Optional, String, NonUpdatable) Specifies the template description.

* `parameters` - (Optional, List, NonUpdatable) Specifies the build execution parameter list.
The [parameters](#block--parameters) structure is documented below.

* `tool_type` - (Optional, String, NonUpdatable) Specifies the tool type.

<a name="block--steps"></a>
The `steps` block supports:

* `module_id` - (Required, String, NonUpdatable) Specifies the build step module ID.

* `name` - (Required, String, NonUpdatable) Specifies the build step name.

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

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

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

<a name="block--parameters"></a>
The `parameters` block supports:

* `name` - (Optional, String, NonUpdatable) Specifies the parameter definition name.

* `params` - (Optional, List, NonUpdatable) Specifies the build execution sub-parameters.
The [params](#block--parameters--params) structure is documented below.

<a name="block--parameters--params"></a>
The `params` block supports:

* `name` - (Optional, String, NonUpdatable) Specifies the parameter field name.

* `value` - (Optional, String, NonUpdatable) Specifies the parameter field value.

* `limits` - (Optional, List, NonUpdatable) Specifies the enumeration parameter restrictions.
The [limits](#block--parameters--params--limits) structure is documented below.

<a name="block--parameters--params--limits"></a>
The `limits` block supports:

* `disable` - (Optional, String, NonUpdatable) Specifies whether it is effective.

* `display_name` - (Optional, String, NonUpdatable) Specifies the displayed name of the parameter.

* `name` - (Optional, String, NonUpdatable) Specifies the parameter name.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `create_time` - Indicates the template creation time.

* `favorite` - Indicates whether the template is favorite.

* `nick_name` - Indicates the nick name.

* `public` - Indicates whether the template is public.

* `scope` - Indicates the scope.

* `steps` - Indicates the build execution steps.
The [steps](#attrblock--steps) structure is documented below.

* `template_id` - Indicates ID in database.

* `type` - Indicates the template type.

* `weight` - Indicates the weight of the template.

<a name="attrblock--steps"></a>
The `steps` block supports:

* `properties_all` - Indicates the build step properties.

## Import

The template can be imported using `id`, e.g.

```bash
$ terraform import huaweicloud_codearts_build_template.test <id>
```
3 changes: 2 additions & 1 deletion huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,8 @@ func Provider() *schema.Provider {
"huaweicloud_codearts_pipeline_template": codeartspipeline.ResourceCodeArtsPipelineTemplate(),
"huaweicloud_codearts_pipeline_service_endpoint": codeartspipeline.ResourceCodeArtsPipelineServiceEndpoint(),

"huaweicloud_codearts_build_task": codeartsbuild.ResourceCodeArtsBuildTask(),
"huaweicloud_codearts_build_task": codeartsbuild.ResourceCodeArtsBuildTask(),
"huaweicloud_codearts_build_template": codeartsbuild.ResourceCodeArtsBuildTemplate(),

"huaweicloud_dsc_instance": dsc.ResourceDscInstance(),
"huaweicloud_dsc_asset_obs": dsc.ResourceAssetObs(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package codeartsbuild

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/codeartsbuild"
)

func getBuildTemplateResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.NewServiceClient("codearts_build", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating CodeArts Build client: %s", err)
}

return codeartsbuild.GetBuildTemplate(client, state.Primary.ID)
}

func TestAccBuildTemplate_basic(t *testing.T) {
var obj interface{}

name := acceptance.RandomAccResourceName()
rName := "huaweicloud_codearts_build_template.test"

rc := acceptance.InitResourceCheck(
rName,
&obj,
getBuildTemplateResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testBuildTemplate_basic(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "description", "demo"),
resource.TestCheckResourceAttrSet(rName, "parameters.#"),
resource.TestCheckResourceAttrSet(rName, "steps.#"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"steps.1.properties"},
},
},
})
}

func testBuildTemplate_basic(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_codearts_build_template" "test" {
name = "%[1]s"
description = "demo"

parameters {
name = "hudson.model.StringParameterDefinition"

params {
name = "name"
value = "test"
}
params {
name = "type"
value = "customizeparam"
}
params {
name = "defaultValue"
value = "cs"
}
params {
name = "staticVar"
value = "false"
}
params {
name = "sensitiveVar"
value = "false"
}
params {
name = "deletion"
value = "false"
}
params {
name = "defaults"
value = "false"
}
}

steps {
enable = true
module_id = "devcloud2018.codeci_action_20035.action"
name = "Docker Command"
}

steps {
enable = true
module_id = "devcloud2018.codeci_action_20057.action"
name = "update OBS"
properties = {
objectKey = jsonencode("./")
backetName = jsonencode("test")
uploadDirectory = jsonencode(true)
artifactSourcePath = jsonencode("bin/*")
authorizationUser = jsonencode({
"displayName": "current user",
"value": "build"
})
obsHeaders = jsonencode([
{
"headerKey": "1",
"headerValue": "1"
}
])
}
}
}
`, name)
}
1 change: 1 addition & 0 deletions huaweicloud/services/codeartsbuild/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
buildTaskNotFoundErr = "DEVCB.00031006"
templateNotFoundErr = "DEV.CB.0520002"
)

// checkResponseError use to check whether the CodeArts Build API response with OkCode but body contains error code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func resourceSchemeTaskSteps() *schema.Resource {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `Specifies the build step properties.`,
Description: `Indicates the build step properties.`,
},
},
}
Expand Down
Loading
Loading