-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cae): add new resource to manage domain name (#6179)
- Loading branch information
1 parent
3beed89
commit 3daf909
Showing
4 changed files
with
401 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,56 @@ | ||
--- | ||
subcategory: "Cloud Application Engine (CAE)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_cae_domain" | ||
description: |- | ||
Manage a CAE domain name resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_cae_domain | ||
|
||
Manage a CAE domain name resource within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "environment_id" {} | ||
variable "domain_name" {} | ||
resource "huaweicloud_cae_domain" "test" { | ||
environment_id = var.environment_id | ||
name = var.domain_name | ||
} | ||
``` | ||
|
||
## 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. | ||
|
||
* `environment_id` - (Required, String, ForceNew) Specifies the ID of the CAE environment. | ||
Changing this creates a new resource. | ||
|
||
* `name` - (Required, String, ForceNew) Specifies the domain name to be associated with the CAE environment. | ||
Changing this creates a new resource. | ||
The maximum length of the domain name is `254` characters. | ||
The domain name consists of multiple strings separated by dots (.), and the maximum length of a single string is `63` characters. | ||
Only letters, digits, and hyphens (-) allowed, and must start with a letter or a digit. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID, in UUID format. | ||
|
||
* `created_at` - The time when the domain name is associated, in RFC3339 format. | ||
|
||
## Import | ||
|
||
The resource can be imported using `environment_id` and `name`, separated by a slash (/), e.g. | ||
|
||
```bash | ||
$ terraform import huaweicloud_cae_domain.test <environment_id>/<name> | ||
``` |
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
106 changes: 106 additions & 0 deletions
106
huaweicloud/services/acceptance/cae/resource_huaweicloud_cae_domain_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,106 @@ | ||
package cae | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cae" | ||
) | ||
|
||
func getResourceDomainFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := cfg.NewServiceClient("cae", acceptance.HW_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating CAE client: %s", err) | ||
} | ||
|
||
return cae.GetDomainById(client, state.Primary.Attributes["environment_id"], state.Primary.ID) | ||
} | ||
|
||
func TestAccResourceDomain_basic(t *testing.T) { | ||
var ( | ||
obj interface{} | ||
|
||
domainName = fmt.Sprintf("%s.com", acceptance.RandomAccResourceNameWithDash()) | ||
|
||
rName = "huaweicloud_cae_domain.test" | ||
rc = acceptance.InitResourceCheck(rName, &obj, getResourceDomainFunc) | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckCaeEnvironment(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
|
||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceDomain_basic(domainName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "environment_id", acceptance.HW_CAE_ENVIRONMENT_ID), | ||
resource.TestCheckResourceAttr(rName, "name", domainName), | ||
resource.TestMatchResourceAttr(rName, "created_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourceDomain_existed(domainName), | ||
ExpectError: regexp.MustCompile(`the domain has already existed`), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateIdFunc: testAccDomainImportFunc(rName), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceDomain_basic(domainName string) string { | ||
return fmt.Sprintf(` | ||
resource "huaweicloud_cae_domain" "test" { | ||
environment_id = "%[1]s" | ||
name = "%[2]s" | ||
} | ||
`, acceptance.HW_CAE_ENVIRONMENT_ID, domainName) | ||
} | ||
|
||
func testAccResourceDomain_existed(domainName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_cae_domain" "test2" { | ||
environment_id = "%[2]s" | ||
name = "%[3]s" | ||
} | ||
`, testAccResourceDomain_basic(domainName), acceptance.HW_CAE_ENVIRONMENT_ID, domainName) | ||
} | ||
|
||
func testAccDomainImportFunc(name string) resource.ImportStateIdFunc { | ||
return func(s *terraform.State) (string, error) { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return "", fmt.Errorf("resource (%s) not found: %s", name, rs) | ||
} | ||
|
||
var ( | ||
environmentId = rs.Primary.Attributes["environment_id"] | ||
domainName = rs.Primary.Attributes["name"] | ||
) | ||
if environmentId == "" || domainName == "" { | ||
return "", fmt.Errorf("some import IDs are missing, want '<environment_id>/<name>', but got '%s/%s'", | ||
environmentId, domainName) | ||
} | ||
|
||
return fmt.Sprintf("%s/%s", environmentId, domainName), nil | ||
} | ||
} |
Oops, something went wrong.