Skip to content

Commit

Permalink
feat(CodeArts/Deploy): support to get applications
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Dec 26, 2024
1 parent 0024aeb commit 226fb39
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 0 deletions.
117 changes: 117 additions & 0 deletions docs/data-sources/codearts_deploy_applications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
subcategory: "CodeArts Deploy"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_codearts_deploy_applications"
description: |-
Use this data source to get the list of CodeArts deploy applications.
---

# huaweicloud_codearts_deploy_applications

Use this data source to get the list of CodeArts deploy applications.

## Example Usage

```hcl
variable "project_id" {}
data "huaweicloud_codearts_deploy_applications" "test" {
project_id = var.project_id
}
```

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

Check failure on line 27 in docs/data-sources/codearts_deploy_applications.md

View workflow job for this annotation

GitHub Actions / markdownlint

Line length [Expected: 120; Actual: 136]

* `project_id` - (Required, String) Specifies the project ID

* `group_id` - (Optional, String) Specifies the application group ID.
Enter **no_grouped** to query ungrouped applications.

* `states` - (Optional, List) Specifies the application status list.
Values can be as follows:
+ **abort**: Deployment suspended.
+ **failed**: Deployment failed.
+ **not_started**: Execution canceled.
+ **pending**: Queuing.
+ **running**: Deployment in progress.
+ **succeeded**: Deployment succeeded.
+ **timeout**: Deployment times out.
+ **not_executed**: Deployment not executed.

## Attribute Reference

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

* `id` - The data source ID.

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

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

* `arrange_infos` - Indicates the deployment task information
The [arrange_infos](#attrblock--applications--arrange_infos) structure is documented below.

* `id` - Indicates the application ID.

* `name` - Indicates the application name.

* `can_copy` - Indicates whether user has permission to clone application.

* `can_create_env` - Indicates whether user has permission to create environment in application.

* `can_delete` - Indicates whether user has permission to delete application.

* `can_disable` - Indicates whether the user has permission to disable application.

* `can_execute` - Indicates whether user has permission to deploy.

* `can_manage` - Indicates whether user has permission to modify application permission.

* `can_modify` - Indicates whether user has permission to modify application.

* `can_view` - Indicates whether user has permission to view application.

* `create_tenant_id` - Indicates the created tenant ID.

* `create_user_id` - Indicates the creator user ID.

* `created_at` - Indicates the created time.

* `deploy_system` - Indicates the deployment type.

* `duration` - Indicates the deployment duration.

* `end_time` - Indicates the deployment end time.

* `execution_state` - Indicates the execution status.

* `execution_time` - Indicates the latest execution time.

* `executor_id` - Indicates the executor user ID.

* `executor_nick_name` - Indicates the executor user name.

* `is_care` - Indicates whether application is saved to favorites.

* `is_disable` - Indicates whether the application is disabled.

* `project_name` - Indicates the project name.

* `release_id` - Indicates the release ID.

* `updated_at` - Indicates the updated time.

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

* `deploy_system` - Indicates the deployment task type.

* `id` - Indicates the task ID.

* `state` - Indicates the deployment task status.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func Provider() *schema.Provider {
"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_cts_notifications": cts.DataSourceNotifications(),
"huaweicloud_cts_traces": cts.DataSourceCtsTraces(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package codeartsdeploy

import (
"fmt"
"testing"

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

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

func TestAccDataSourceCodeartsDeployApplications_basic(t *testing.T) {
dataSource := "data.huaweicloud_codearts_deploy_applications.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: testDataSourceCodeartsDeployApplications_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "applications.#"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.project_name"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.name"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.release_id"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_modify"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_manage"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_create_env"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_execute"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_copy"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_delete"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_view"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.can_disable"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.is_care"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.is_disable"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.create_user_id"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.create_tenant_id"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.created_at"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.updated_at"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.arrange_infos.#"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.arrange_infos.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.arrange_infos.0.state"),
resource.TestCheckResourceAttrSet(dataSource, "applications.0.arrange_infos.0.deploy_system"),

resource.TestCheckOutput("is_state_filter_useful", "true"),
),
},
},
})
}

func testDataSourceCodeartsDeployApplications_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_codearts_deploy_applications" "test" {
depends_on = [huaweicloud_codearts_deploy_application.test]
project_id = huaweicloud_codearts_project.test.id
}
// filter by state
data "huaweicloud_codearts_deploy_applications" "filter_by_state" {
depends_on = [huaweicloud_codearts_deploy_application.test]
project_id = huaweicloud_codearts_project.test.id
states = ["not_executed"]
}
locals {
filter_result_by_state = [for v in data.huaweicloud_codearts_deploy_applications.filter_by_state.applications[*].arrange_infos[0].state :
v == "Draft"]
}
output "is_state_filter_useful" {
value = length(local.filter_result_by_state) == 1 && alltrue(local.filter_result_by_state)
}
`, testDeployApplication_basic(name))
}
Loading

0 comments on commit 226fb39

Please sign in to comment.