-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ges): import ges_metadata resource and doc
- Loading branch information
1 parent
85f4c3f
commit 14c021d
Showing
3 changed files
with
315 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,136 @@ | ||
--- | ||
subcategory: "Graph Engine Service (GES)" | ||
--- | ||
|
||
# g42cloud_ges_metadata | ||
|
||
Manages a GES metadata resource within G42Cloud. | ||
|
||
-> Only 50 metadata resources can be created. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "obs_path" {} | ||
resource "g42cloud_ges_metadata" "test" { | ||
name = "demo" | ||
description = "This is a demo" | ||
metadata_path = var.obs_path | ||
ges_metadata { | ||
labels { | ||
name = "user" | ||
properties = [{ | ||
"dataType" = "char" | ||
"name" = "sex" | ||
"cardinality" = "single" | ||
}, | ||
{ | ||
"dataType" = "enum" | ||
"name" = "country" | ||
"cardinality" = "single" | ||
"typeNameCount" = "3" | ||
"typeName1" = "US" | ||
"typeName2" = "EN" | ||
"typeName3" = "CN" | ||
}, | ||
{ | ||
"dataType" = "char array" | ||
"name" = "firstName" | ||
"cardinality" = "single" | ||
"maxDataSize" = "20" | ||
}, | ||
{ | ||
"dataType" = "string" | ||
"name" = "lastName" | ||
"cardinality" = "single" | ||
}, | ||
{ | ||
"dataType" = "long" | ||
"name" = "children" | ||
"cardinality" = "set" | ||
}, | ||
{ | ||
"dataType" = "long" | ||
"name" = "friends" | ||
"cardinality" = "list" | ||
}, | ||
{ | ||
"dataType" = "enum" | ||
"name" = "cards" | ||
"cardinality" = "list" | ||
"typeNameCount" = "3" | ||
"typeName1" = "card_1" | ||
"typeName2" = "card_2" | ||
"typeName3" = "card_3" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 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 parameter will create a new resource. | ||
|
||
* `name` - (Required, String, ForceNew) Metadata name. | ||
The name contains 1 to 64 characters consisting of only letters, digits, and underscores (_). | ||
Changing this parameter will create a new resource. | ||
|
||
* `metadata_path` - (Required, String) OBS Path for storing the metadata. | ||
|
||
* `description` - (Required, String, ForceNew) Metadata description. | ||
|
||
Changing this parameter will create a new resource. | ||
|
||
* `ges_metadata` - (Required, List) Object for storing metadata message information. | ||
The [ges_metadata](#GesMetadata_Metadata) structure is documented below. | ||
|
||
* `encryption` - (Optional, List) The configuration of data encryption. | ||
The graph instance is not encrypted by default. | ||
The [encryption](#GesMetadata_Encryption) structure is documented below. | ||
|
||
<a name="GesMetadata_Metadata"></a> | ||
The `ges_metadata` block supports: | ||
|
||
* `labels` - (Optional, List) Label list. | ||
For details, see [data formats](https://docs.g42cloud.com/usermanual/ges/ges_01_0153.html). | ||
The [labels](#GesMetadata_MetadataLabels) structure is documented below. | ||
|
||
<a name="GesMetadata_MetadataLabels"></a> | ||
The `labels` block supports: | ||
|
||
* `name` - (Optional, String) Name of a label. | ||
|
||
* `properties` - (Optional, List) The list of label properties. A property refers to the data format of a single | ||
property and contains some fields. | ||
For details, see [data formats](https://docs.g42cloud.com/usermanual/ges/ges_01_0153.html). | ||
|
||
<a name="GesMetadata_Encryption"></a> | ||
The `encryption` block supports: | ||
|
||
* `enable` - (Optional, Bool) Whether to enable data encryption The value can be true or false. | ||
The default value is false. | ||
|
||
* `master_key_id` - (Optional, String) ID of the customer master key created by DEW in the project where | ||
the graph is created. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID. | ||
|
||
* `status` - Status of a metadata. **200** is available. | ||
|
||
## Import | ||
|
||
The ges metadata can be imported using the `id`, e.g. | ||
|
||
```bash | ||
terraform import g42cloud_ges_metadata.test 55b32ad9-1aba-407d-86cf-85f4f765d37a | ||
``` |
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
168 changes: 168 additions & 0 deletions
168
g42cloud/services/acceptance/ges/resource_g42cloud_ges_metadata_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,168 @@ | ||
package ges | ||
|
||
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/g42cloud-terraform/terraform-provider-g42cloud/g42cloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" | ||
) | ||
|
||
func getGesMetadataResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { | ||
region := acceptance.G42_REGION_NAME | ||
// getMetadataDetail: Query the GES metadata detail. | ||
var ( | ||
getMetadataDetailHttpUrl = "v1.0/{project_id}/graphs/metadatas/{id}" | ||
getMetadataDetailProduct = "ges" | ||
) | ||
getMetadataDetailClient, err := cfg.NewServiceClient(getMetadataDetailProduct, region) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating GES Client: %s", err) | ||
} | ||
|
||
getMetadataDetailPath := getMetadataDetailClient.Endpoint + getMetadataDetailHttpUrl | ||
getMetadataDetailPath = strings.ReplaceAll(getMetadataDetailPath, "{project_id}", getMetadataDetailClient.ProjectID) | ||
getMetadataDetailPath = strings.ReplaceAll(getMetadataDetailPath, "{id}", state.Primary.ID) | ||
|
||
getMetadataDetailOpt := golangsdk.RequestOpts{ | ||
KeepResponseBody: true, | ||
OkCodes: []int{ | ||
200, | ||
}, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json;charset=UTF-8"}, | ||
} | ||
|
||
getMetadataDetailResp, err := getMetadataDetailClient.Request("GET", getMetadataDetailPath, &getMetadataDetailOpt) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving GES metadata: %s", err) | ||
} | ||
|
||
getMetadataDetailRespBody, err := utils.FlattenResponse(getMetadataDetailResp) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving GES metadata: %s", err) | ||
} | ||
|
||
return getMetadataDetailRespBody, nil | ||
} | ||
|
||
func TestAccGesMetadata_basic(t *testing.T) { | ||
var obj interface{} | ||
|
||
name := acceptance.RandomAccResourceName() | ||
rName := "g42cloud_ges_metadata.test" | ||
bucketName := acceptance.RandomAccResourceNameWithDash() | ||
|
||
rc := acceptance.InitResourceCheck( | ||
rName, | ||
&obj, | ||
getGesMetadataResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testGesMetadata_basic(name, bucketName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "name", name), | ||
resource.TestCheckResourceAttr(rName, "description", "This is a demo"), | ||
resource.TestCheckResourceAttr(rName, "ges_metadata.0.labels.0.properties.#", "1"), | ||
resource.TestCheckResourceAttrSet(rName, "status"), | ||
), | ||
}, | ||
{ | ||
Config: testGesMetadata_basic_update(name, bucketName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "name", name), | ||
resource.TestCheckResourceAttr(rName, "description", "This is a demo"), | ||
resource.TestCheckResourceAttr(rName, "ges_metadata.0.labels.0.properties.#", "2"), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testGesMetadata_basic(name, bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "g42cloud_obs_bucket" "test" { | ||
bucket = "%s" | ||
acl = "private" | ||
force_destroy = true | ||
} | ||
resource "g42cloud_ges_metadata" "test" { | ||
name = "%s" | ||
description = "This is a demo" | ||
metadata_path = "${g42cloud_obs_bucket.test.bucket}/schema_%s.xml" | ||
ges_metadata { | ||
labels { | ||
name = "user" | ||
properties = [{ | ||
"dataType" = "char" | ||
"name" = "sex" | ||
"cardinality" = "single" | ||
}] | ||
} | ||
} | ||
depends_on = [ | ||
g42cloud_obs_bucket.test | ||
] | ||
} | ||
`, bucketName, name, name) | ||
} | ||
|
||
func testGesMetadata_basic_update(name, bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "g42cloud_obs_bucket" "test" { | ||
bucket = "%s" | ||
acl = "private" | ||
force_destroy = true | ||
} | ||
resource "g42cloud_ges_metadata" "test" { | ||
name = "%s" | ||
description = "This is a demo" | ||
metadata_path = "${g42cloud_obs_bucket.test.bucket}/schema_%s.xml" | ||
ges_metadata { | ||
labels { | ||
name = "user" | ||
properties = [{ | ||
"dataType" = "char" | ||
"name" = "sex" | ||
"cardinality" = "single" | ||
}, | ||
{ | ||
"dataType" = "enum" | ||
"name" = "country" | ||
"cardinality" = "single" | ||
"typeNameCount" = "3" | ||
"typeName1" = "US" | ||
"typeName2" = "EN" | ||
"typeName3" = "CN" | ||
}] | ||
} | ||
} | ||
depends_on = [ | ||
g42cloud_obs_bucket.test | ||
] | ||
} | ||
`, bucketName, name, name) | ||
} |