-
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 copy application
- Loading branch information
Showing
4 changed files
with
186 additions
and
0 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,38 @@ | ||
--- | ||
subcategory: "CodeArts Deploy" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_codearts_deploy_application_copy" | ||
description: |- | ||
Manages a CodeArts deploy application copy resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_codearts_deploy_application_copy | ||
|
||
Manages a CodeArts deploy application copy resource within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "app_id" {} | ||
resource "huaweicloud_codearts_deploy_application_copy" "test" { | ||
app_id = var.app_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. | ||
|
||
* `app_id` - (Required, String, ForceNew) Specifies the application ID. | ||
Changing this creates a new resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID, is same as the new application 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
59 changes: 59 additions & 0 deletions
59
...s/acceptance/codeartsdeploy/resource_huaweicloud_codearts_deploy_application_copy_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,59 @@ | ||
package codeartsdeploy | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccCodeArtsDeployApplicationCopy_basic(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testCodeArtsDeployApplicationCopy_basic(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckOutput("applications_len_before_copy", "true"), | ||
resource.TestCheckOutput("applications_len_after_copy", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCodeArtsDeployApplicationCopy_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "huaweicloud_codearts_deploy_applications" "beforeCopy" { | ||
depends_on = [huaweicloud_codearts_deploy_application.test] | ||
project_id = huaweicloud_codearts_project.test.id | ||
} | ||
resource "huaweicloud_codearts_deploy_application_copy" "test" { | ||
app_id = huaweicloud_codearts_deploy_application.test.id | ||
} | ||
data "huaweicloud_codearts_deploy_applications" "afterCopy" { | ||
depends_on = [huaweicloud_codearts_deploy_application_copy.test] | ||
project_id = huaweicloud_codearts_project.test.id | ||
} | ||
output "applications_len_before_copy" { | ||
value = length(data.huaweicloud_codearts_deploy_applications.beforeCopy.applications) == 1 | ||
} | ||
output "applications_len_after_copy" { | ||
value = length(data.huaweicloud_codearts_deploy_applications.afterCopy.applications) == 2 | ||
} | ||
`, testDeployApplication_basic(name)) | ||
} |
88 changes: 88 additions & 0 deletions
88
huaweicloud/services/codeartsdeploy/resource_huaweicloud_codearts_deploy_application_copy.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,88 @@ | ||
package codeartsdeploy | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"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" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" | ||
) | ||
|
||
// @API CodeArtsDeploy POST /v1/applications/{app_id}/duplicate | ||
func ResourceDeployApplicationCopy() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceCodeArtsDeployApplicationCopyCreate, | ||
ReadContext: resourceCodeArtsDeployApplicationCopyRead, | ||
DeleteContext: resourceCodeArtsDeployApplicationCopyDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"app_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `Specifies the application ID.`, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceCodeArtsDeployApplicationCopyCreate(_ 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) | ||
} | ||
|
||
httpUrl := "v1/applications/{app_id}/duplicate" | ||
createPath := client.Endpoint + httpUrl | ||
createPath = strings.ReplaceAll(createPath, "{app_id}", d.Get("app_id").(string)) | ||
createOpt := golangsdk.RequestOpts{ | ||
KeepResponseBody: true, | ||
} | ||
|
||
createResp, err := client.Request("POST", createPath, &createOpt) | ||
if err != nil { | ||
return diag.Errorf("error copying CodeArts deploy application: %s", err) | ||
} | ||
|
||
createRespBody, err := utils.FlattenResponse(createResp) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
copyId := utils.PathSearch("result.id", createRespBody, "").(string) | ||
if copyId == "" { | ||
return diag.Errorf("unable to find the CodeArts deploy new application ID from the API response") | ||
} | ||
|
||
d.SetId(copyId) | ||
|
||
return nil | ||
} | ||
|
||
func resourceCodeArtsDeployApplicationCopyRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
return nil | ||
} | ||
|
||
func resourceCodeArtsDeployApplicationCopyDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
errorMsg := "Deleting application copy resource is not supported. The resource is only removed from the" + | ||
"state, the application remain in the cloud." | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: errorMsg, | ||
}, | ||
} | ||
} |