-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CodeArts/Deploy): support to move application group
- Loading branch information
Showing
4 changed files
with
243 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ptance/codeartsdeploy/resource_huaweicloud_codearts_deploy_application_group_move_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
104 changes: 104 additions & 0 deletions
104
...ud/services/codeartsdeploy/resource_huaweicloud_codearts_deploy_application_group_move.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
} |