Skip to content

Commit

Permalink
feat(CodeArts/Deploy): support to deploy app and get deployment records
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Jan 20, 2025
1 parent dbab65f commit d339247
Show file tree
Hide file tree
Showing 11 changed files with 861 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
subcategory: "CodeArts Deploy"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_codearts_deploy_application_deployment_records"
description: |-
Use this data source to get the list of CodeArts deploy application deployment records.
---

# huaweicloud_codearts_deploy_application_deployment_records

Use this data source to get the list of CodeArts deploy application deployment records.

## Example Usage

```hcl
variable "project_id" {}
variable "task_id" {}
variable "start_date" {}
variable "end_date" {}
data "huaweicloud_codearts_deploy_application_deployment_records" "test" {
project_id = var.project_id
task_id = var.task_id
start_date = var.start_date
end_date = var.end_date
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the resource.
If omitted, the provider-level region will be used.

* `project_id` - (Required, String) Specifies the project ID for CodeArts service.

* `task_id` - (Required, String) Specifies the deployment task ID.

* `start_date` - (Required, String) Specifies the start time. The value format is **yyyy-mm-dd**.

* `end_date` - (Required, String) Specifies the end time. The value format is **yyyy-mm-dd**.

## Attribute Reference

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

* `id` - The data source ID.

* `records` - Indicates the record list.
The [records](#attrblock--records) structure is documented below.

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

* `id` - Indicates the record ID.

* `duration` - Indicates the deployment duration.

* `operator` - Indicates the operator user name.

* `release_id` - Indicates the deployment record sequence number.

* `state` - Indicates the application status.

* `start_time` - Indicates the start time of application deployment. The value format is **yyyy-mm-dd hh:mm:ss**.

* `end_time` - Indicates the end time of application deployment. The value format is **yyyy-mm-dd hh:mm:ss**.

* `type` - Indicates the deployment type.
94 changes: 94 additions & 0 deletions docs/resources/codearts_deploy_application_deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
subcategory: "CodeArts Deploy"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_codearts_deploy_application_deploy"
description: |-
Manages a CodeArts deploy application deploy resource within HuaweiCloud.
---

# huaweicloud_codearts_deploy_application_deploy

Manages a CodeArts deploy application deploy resource within HuaweiCloud.

## Example Usage

```hcl
variable "task_id" {}
resource "huaweicloud_codearts_deploy_application_deploy" "test" {
task_id = var.task_id
}
```

## 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.

* `task_id` - (Required, String, ForceNew) Specifies the deployment task ID.
Changing this creates a new resource.

* `params` - (Optional, List, ForceNew) Specifies the parameters transferred during application deployment.
Changing this creates a new resource.
The [params](#block--params) structure is documented below.

* `record_id` - (Optional, String, ForceNew) Specifies the deployment record ID of an application. Specifies it to roll
back the application to the previous deployment status.
Changing this creates a new resource.

* `trigger_source` - (Optional, String, ForceNew) Specifies the trigger source.
Valid values are as follows:
+ **0**: Deployment can be triggered through all requests.
+ **1**: Deployment can be triggered only through pipeline.

Changing this creates a new resource.

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

* `name` - (Optional, String, ForceNew) Specifies the parameter name transferred when deploying application.
Changing this creates a new resource.

* `type` - (Optional, String, ForceNew) Specifies the parameter type. If a dynamic parameter is set, the type is mandatory.
Changing this creates a new resource.

* `value` - (Optional, String, ForceNew) Specifies the parameter value transferred during application deployment.
Changing this creates a new resource.

## Attribute Reference

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

* `id` - The resource ID.

## Import

The application deployment record can be imported using `task_id`, and `id`, separated by a slash, e.g.

```bash
$ terraform import huaweicloud_codearts_deploy_application_deploy.test <task_id>/<id>
```

Please add the followings if some attributes are missing when importing the resource.

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
API response, security or some other reason.
The missing attributes include: `params`, `record_id` and `trigger_source`.
It is generally recommended running `terraform plan` after importing the resource.
You can then decide if changes should be applied to the deployment record, or the resource definition should be updated to
align with the deployment record. Also you can ignore changes as below.

```hcl
resource "huaweicloud_codearts_deploy_application_deploy" "test" {
...
lifecycle {
ignore_changes = [
params, record_id, trigger_source,
]
}
}
```
12 changes: 7 additions & 5 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,12 @@ func Provider() *schema.Provider {
"huaweicloud_compute_servergroups": ecs.DataSourceComputeServerGroups(),
"huaweicloud_compute_instance_remote_console": ecs.DataSourceComputeInstanceRemoteConsole(),

"huaweicloud_codearts_deploy_groups": codeartsdeploy.DataSourceCodeartsDeployGroups(),
"huaweicloud_codearts_deploy_hosts": codeartsdeploy.DataSourceCodeartsDeployHosts(),
"huaweicloud_codearts_deploy_application_groups": codeartsdeploy.DataSourceCodeartsDeployApplicationGroups(),
"huaweicloud_codearts_deploy_applications": codeartsdeploy.DataSourceCodeartsDeployApplications(),
"huaweicloud_codearts_deploy_environments": codeartsdeploy.DataSourceCodeartsDeployEnvironments(),
"huaweicloud_codearts_deploy_groups": codeartsdeploy.DataSourceCodeartsDeployGroups(),
"huaweicloud_codearts_deploy_hosts": codeartsdeploy.DataSourceCodeartsDeployHosts(),
"huaweicloud_codearts_deploy_application_groups": codeartsdeploy.DataSourceCodeartsDeployApplicationGroups(),
"huaweicloud_codearts_deploy_applications": codeartsdeploy.DataSourceCodeartsDeployApplications(),
"huaweicloud_codearts_deploy_application_deployment_records": codeartsdeploy.DataSourceCodeartsDeployApplicationDeploymentRecords(),
"huaweicloud_codearts_deploy_environments": codeartsdeploy.DataSourceCodeartsDeployEnvironments(),

"huaweicloud_cts_notifications": cts.DataSourceNotifications(),
"huaweicloud_cts_traces": cts.DataSourceCtsTraces(),
Expand Down Expand Up @@ -2256,6 +2257,7 @@ func Provider() *schema.Provider {

"huaweicloud_codearts_deploy_application": codeartsdeploy.ResourceDeployApplication(),
"huaweicloud_codearts_deploy_application_permission": codeartsdeploy.ResourceDeployApplicationPermission(),
"huaweicloud_codearts_deploy_application_deploy": codeartsdeploy.ResourceDeployApplicationDeploy(),
"huaweicloud_codearts_deploy_application_group": codeartsdeploy.ResourceDeployApplicationGroup(),
"huaweicloud_codearts_deploy_application_group_move": codeartsdeploy.ResourceDeployApplicationGroupMove(),
"huaweicloud_codearts_deploy_environment": codeartsdeploy.ResourceDeployEnvironment(),
Expand Down
11 changes: 10 additions & 1 deletion huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ var (
HW_NEW_GM_ENC_CERTIFICATE_PRIVATE_KEY = os.Getenv("HW_NEW_GM_ENC_CERTIFICATE_PRIVATE_KEY")
HW_NEW_GM_CERTIFICATE_CHAIN = os.Getenv("HW_NEW_GM_CERTIFICATE_CHAIN")

HW_CODEARTS_RESOURCE_POOL_ID = os.Getenv("HW_CODEARTS_RESOURCE_POOL_ID")
HW_CODEARTS_RESOURCE_POOL_ID = os.Getenv("HW_CODEARTS_RESOURCE_POOL_ID")
HW_CODEARTS_DEPLOYMENT_TASK_ID = os.Getenv("HW_CODEARTS_DEPLOYMENT_TASK_ID")

HW_CODEARTS_ENABLE_FLAG = os.Getenv("HW_CODEARTS_ENABLE_FLAG")
HW_CODEARTS_PUBLIC_IP_ADDRESS = os.Getenv("HW_CODEARTS_PUBLIC_IP_ADDRESS")

Expand Down Expand Up @@ -1895,6 +1897,13 @@ func TestAccPreCheckCodeArtsDeployResourcePoolID(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckCodeArtsDeploymentTaskID(t *testing.T) {
if HW_CODEARTS_DEPLOYMENT_TASK_ID == "" {
t.Skip("HW_CODEARTS_DEPLOYMENT_TASK_ID must be set for this acceptance test")
}
}

// lintignore:AT003
func TestAccPreCheckCodeArtsEnableFlag(t *testing.T) {
if HW_CODEARTS_ENABLE_FLAG == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package codeartsdeploy

import (
"fmt"
"strings"
"testing"
"time"

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

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

func TestAccDataSourceCodeartsDeployApplicationDeploymentRecords_basic(t *testing.T) {
dataSource := "data.huaweicloud_codearts_deploy_application_deployment_records.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceCodeartsDeployApplicationDeploymentRecords_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSource, "records.#", "1"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.start_time"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.end_time"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.duration"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.state"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.operator"),
resource.TestCheckResourceAttrSet(dataSource, "records.0.release_id"),
),
},
},
})
}

func testDataSourceCodeartsDeployApplicationDeploymentRecords_basic(name string) string {
date := strings.Split(time.Now().Format("2006-01-02T15:04:05Z"), "T")[0]

return fmt.Sprintf(`
%[1]s
data "huaweicloud_codearts_deploy_application_deployment_records" "test" {
depends_on = [huaweicloud_codearts_deploy_application_deploy.test]
project_id = huaweicloud_codearts_project.test.id
task_id = huaweicloud_codearts_deploy_application.test.task_id
start_date = "%[2]s"
end_date = "%[2]s"
}
`, testAccDeployApplicationDeploy_basic(name), date)
}
Loading

0 comments on commit d339247

Please sign in to comment.