Skip to content

Commit

Permalink
feat(CodeArts/Deploy): support to move application group
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Dec 25, 2024
1 parent c922c73 commit 4fac7f7
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 6 deletions.
52 changes: 52 additions & 0 deletions docs/resources/codearts_deploy_application_group_move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
subcategory: "CodeArts Deploy"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_codearts_deploy_application_group_move"
description: |-
Manages a CodeArts deploy application group move resource within HuaweiCloud.
---

# huaweicloud_codearts_deploy_application_group_move

Manages a CodeArts deploy application group move resource within HuaweiCloud.

## Example Usage

```hcl
variable "project_id" {}
variable "group_id" {}
variable "movement" {}
resource "huaweicloud_codearts_deploy_application_group" "test" {
project_id = var.project_id
group_id = var.group_id
movement = var.movement
}
```

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

* `project_id` - (Required, String, ForceNew) Specifies the project ID for CodeArts service.
Changing this creates a new resource.

* `group_id` - (Required, String, ForceNew) Specifies the application group ID.
Changing this creates a new resource.

* `movement` - (Required, Int, ForceNew) Specifies the moving direction.
Valid values are as follows:
+ **1**: Upward.
+ **-1**: Downward.

Changing this creates a new resource.

## Attribute Reference

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

* `id` - The resource ID.
13 changes: 7 additions & 6 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2211,12 +2211,13 @@ func Provider() *schema.Provider {
"huaweicloud_codearts_project": codearts.ResourceProject(),
"huaweicloud_codearts_repository": codearts.ResourceRepository(),

"huaweicloud_codearts_deploy_application": codeartsdeploy.ResourceDeployApplication(),
"huaweicloud_codearts_deploy_application_group": codeartsdeploy.ResourceDeployApplicationGroup(),
"huaweicloud_codearts_deploy_group": codeartsdeploy.ResourceDeployGroup(),
"huaweicloud_codearts_deploy_group_permission": codeartsdeploy.ResourceDeployGroupPermission(),
"huaweicloud_codearts_deploy_host": codeartsdeploy.ResourceDeployHost(),
"huaweicloud_codearts_deploy_hosts_copy": codeartsdeploy.ResourceCodeArtsDeployHostsCopy(),
"huaweicloud_codearts_deploy_application": codeartsdeploy.ResourceDeployApplication(),
"huaweicloud_codearts_deploy_application_group": codeartsdeploy.ResourceDeployApplicationGroup(),
"huaweicloud_codearts_deploy_application_group_move": codeartsdeploy.ResourceDeployApplicationGroupMove(),
"huaweicloud_codearts_deploy_group": codeartsdeploy.ResourceDeployGroup(),
"huaweicloud_codearts_deploy_group_permission": codeartsdeploy.ResourceDeployGroupPermission(),
"huaweicloud_codearts_deploy_host": codeartsdeploy.ResourceDeployHost(),
"huaweicloud_codearts_deploy_hosts_copy": codeartsdeploy.ResourceCodeArtsDeployHostsCopy(),

"huaweicloud_codearts_inspector_website": codeartsinspector.ResourceInspectorWebsite(),
"huaweicloud_codearts_inspector_website_scan": codeartsinspector.ResourceInspectorWebsiteScan(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package codeartsdeploy

import (
"fmt"
"testing"

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

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

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

name := acceptance.RandomAccResourceName()
rName := "huaweicloud_codearts_deploy_application_group.test2"

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testDeployApplicationGroupMove_base(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "ordinal", "2"),
),
},
{
Config: testDeployApplicationGroupMove_basic(name),
},
{
Config: testDeployApplicationGroupMove_basic(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "ordinal", "1"),
),
},
},
})
}

func testDeployApplicationGroupMove_base(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_codearts_deploy_application_group" "test1" {
project_id = huaweicloud_codearts_project.test.id
name = "%[2]s-1"
}
resource "huaweicloud_codearts_deploy_application_group" "test2" {
depends_on = [huaweicloud_codearts_deploy_application_group.test1]
project_id = huaweicloud_codearts_project.test.id
name = "%[2]s-2"
}
`, testProject_basic(name), name)
}

func testDeployApplicationGroupMove_basic(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_codearts_deploy_application_group_move" "test" {
project_id = huaweicloud_codearts_project.test.id
group_id = huaweicloud_codearts_deploy_application_group.test2.id
movement = -1
}
`, testDeployApplicationGroupMove_base(name))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package codeartsdeploy

import (
"context"
"strings"

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/chnsz/golangsdk"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
)

// @API CodeArtsDeploy PUT /v1/projects/{project_id}/applications/groups/swap
func ResourceDeployApplicationGroupMove() *schema.Resource {
return &schema.Resource{
CreateContext: resourceDeployApplicationGroupMoveCreate,
ReadContext: resourceDeployApplicationGroupMoveRead,
DeleteContext: resourceDeployApplicationGroupMoveDelete,

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"project_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Specifies the project ID for CodeArts service.`,
},
"group_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Specifies the application group ID.`,
},
"movement": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `Specifies the moving direction. 1: Upward. -1: Downward.`,
},
},
}
}

func resourceDeployApplicationGroupMoveCreate(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
cfg := meta.(*config.Config)
region := cfg.GetRegion(d)
client, err := cfg.NewServiceClient("codearts_deploy", region)
if err != nil {
return diag.Errorf("error creating CodeArts deploy client: %s", err)
}

createHttpUrl := "v1/projects/{project_id}/applications/groups/swap"
createPath := client.Endpoint + createHttpUrl
createPath = strings.ReplaceAll(createPath, "{project_id}", d.Get("project_id").(string))
createOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
JSONBody: buildCreateDeployApplicationGroupMoveBodyParams(d),
}

_, err = client.Request("PUT", createPath, &createOpt)
if err != nil {
return diag.Errorf("error moving application group: %s", err)
}

id, err := uuid.GenerateUUID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)

return nil
}

func buildCreateDeployApplicationGroupMoveBodyParams(d *schema.ResourceData) map[string]interface{} {
bodyParams := map[string]interface{}{
"id": d.Get("group_id"),
"movement": d.Get("movement"),
}

return bodyParams
}

func resourceDeployApplicationGroupMoveRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
return nil
}

func resourceDeployApplicationGroupMoveDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
errorMsg := "Deleting application group move resource is not supported. The resource is only removed from the state," +
" the application group remains in the cloud."
return diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Warning,
Summary: errorMsg,
},
}
}

0 comments on commit 4fac7f7

Please sign in to comment.