diff --git a/docs/incubating/coc_script.md b/docs/incubating/coc_script.md new file mode 100644 index 0000000000..e1f14a2fb4 --- /dev/null +++ b/docs/incubating/coc_script.md @@ -0,0 +1,80 @@ +--- +subcategory: "Cloud Operations Center (COC)" +--- + +# huaweicloud_coc_script + +Manages COC script resource within HuaweiCloud. + +## Example Usage + +```hcl +resource "huaweicloud_coc_script" "test" { + name = "demo" + description = "a demo script" + risk_level = "LOW" + version = "1.0.0" + type = "SHELL" + + content = < +The `parameters` block supports: + +* `name` - (Required, String) Specifies the name of the parameter. + +* `value` - (Required, String) Specifies the **default** value of the parameter. + +* `description` - (Required, String) Specifies the description of the parameter. + +* `sensitive` - (Optional, Bool) Specifies whether the parameter is sensitive. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The resource ID. +* `status` - The status of the script. +* `created_at` - The creation time of the script. +* `updated_at` - The latest update time of the script. + +## Import + +The COC script can be imported using `id`, e.g. + +```bash +$ terraform import huaweicloud_coc_script.test +``` diff --git a/huaweicloud/config/endpoints.go b/huaweicloud/config/endpoints.go index fb90d302ee..7df5278dd4 100644 --- a/huaweicloud/config/endpoints.go +++ b/huaweicloud/config/endpoints.go @@ -206,6 +206,12 @@ var allServiceCatalog = map[string]ServiceCatalog{ Version: "svcstg/icmgr/v1", Product: "AOM", }, + "coc": { + Name: "coc", + Version: "v1", + Scope: "global", + Product: "COC", + }, "fgs": { Name: "functiongraph", Version: "v2", diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 3b3c15ec33..d732e77da4 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -33,6 +33,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cloudtable" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cmdb" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cnad" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/coc" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/codearts" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cph" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cpts" @@ -813,6 +814,8 @@ func Provider() *schema.Provider { "huaweicloud_compute_eip_associate": ecs.ResourceComputeEIPAssociate(), "huaweicloud_compute_volume_attach": ecs.ResourceComputeVolumeAttach(), + "huaweicloud_coc_script": coc.ResourceScript(), + "huaweicloud_cph_server": cph.ResourceCphServer(), "huaweicloud_cse_microservice": cse.ResourceMicroservice(), diff --git a/huaweicloud/services/acceptance/coc/resource_huaweicloud_coc_script_test.go b/huaweicloud/services/acceptance/coc/resource_huaweicloud_coc_script_test.go new file mode 100644 index 0000000000..00180e8f58 --- /dev/null +++ b/huaweicloud/services/acceptance/coc/resource_huaweicloud_coc_script_test.go @@ -0,0 +1,146 @@ +package coc + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" +) + +func getScriptResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { + client, err := conf.NewServiceClient("coc", acceptance.HW_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating COC client: %s", err) + } + + getScriptHttpUrl := "v1/job/scripts/{id}" + getScriptPath := client.Endpoint + getScriptHttpUrl + getScriptPath = strings.ReplaceAll(getScriptPath, "{id}", state.Primary.ID) + + getScriptOpt := golangsdk.RequestOpts{ + KeepResponseBody: true, + MoreHeaders: map[string]string{"Content-Type": "application/json"}, + } + + getScriptResp, err := client.Request("GET", getScriptPath, &getScriptOpt) + if err != nil { + return nil, fmt.Errorf("error retrieving COC script: %s", err) + } + + getScriptRespBody, err := utils.FlattenResponse(getScriptResp) + if err != nil { + return nil, fmt.Errorf("error retrieving COC script: %s", err) + } + + return getScriptRespBody, nil +} + +func TestAccScript_basic(t *testing.T) { + var obj interface{} + rName := acceptance.RandomAccResourceName() + resourceName := "huaweicloud_coc_script.test" + + rc := acceptance.InitResourceCheck( + resourceName, + &obj, + getScriptResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acceptance.TestAccPreCheck(t) + acceptance.TestAccPreCheckInternal(t) + }, + ProviderFactories: acceptance.TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: tesScript_basic(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "description", "a demo script"), + resource.TestCheckResourceAttr(resourceName, "risk_level", "LOW"), + resource.TestCheckResourceAttr(resourceName, "version", "1.0.0"), + resource.TestCheckResourceAttr(resourceName, "parameters.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "created_at"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: tesScript_updated(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "description", "a new demo script"), + resource.TestCheckResourceAttr(resourceName, "risk_level", "MEDIUM"), + resource.TestCheckResourceAttr(resourceName, "version", "1.0.1"), + resource.TestCheckResourceAttr(resourceName, "parameters.#", "2"), + resource.TestCheckResourceAttrSet(resourceName, "created_at"), + resource.TestCheckResourceAttrSet(resourceName, "updated_at"), + ), + }, + }, + }) +} + +func tesScript_basic(name string) string { + return fmt.Sprintf(` +resource "huaweicloud_coc_script" "test" { + name = "%s" + description = "a demo script" + risk_level = "LOW" + version = "1.0.0" + type = "SHELL" + + content = <