From 5592c9e8e46fd0018fabd5c2d38158031dcaa2b0 Mon Sep 17 00:00:00 2001 From: chenhanzhang Date: Thu, 26 Dec 2024 09:36:33 +0800 Subject: [PATCH] resource/alicloud_cr_ee_instance: add new attribute instance_endpoints. --- alicloud/resource_alicloud_cr_ee_instance.go | 73 ++++++++++++++++++- .../resource_alicloud_cr_ee_instance_test.go | 7 +- alicloud/service_alicloud_cr_v2.go | 43 ++++++++++- website/docs/r/cr_ee_instance.html.markdown | 31 ++++---- 4 files changed, 131 insertions(+), 23 deletions(-) diff --git a/alicloud/resource_alicloud_cr_ee_instance.go b/alicloud/resource_alicloud_cr_ee_instance.go index 2d753e1a3001..4c1b68b4c0f2 100644 --- a/alicloud/resource_alicloud_cr_ee_instance.go +++ b/alicloud/resource_alicloud_cr_ee_instance.go @@ -51,6 +51,38 @@ func resourceAliCloudCrInstance() *schema.Resource { Optional: true, ValidateFunc: StringInSlice([]string{"ACR", "SAS"}, false), }, + "instance_endpoints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "domains": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Computed: true, + }, + "domain": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "endpoint_type": { + Type: schema.TypeString, + Computed: true, + }, + "enable": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, "instance_name": { Type: schema.TypeString, Required: true, @@ -259,8 +291,8 @@ func resourceAliCloudCrInstanceRead(d *schema.ResourceData, meta interface{}) er d.Set("status", objectRaw["InstanceStatus"]) } - objectRaw, err = crServiceV2.DescribeQueryAvailableInstances(d.Id()) - if err != nil { + objectRaw, err = crServiceV2.DescribeInstanceQueryAvailableInstances(d.Id()) + if err != nil && !NotFoundError(err) { return WrapError(err) } @@ -286,6 +318,43 @@ func resourceAliCloudCrInstanceRead(d *schema.ResourceData, meta interface{}) er d.Set("renewal_status", objectRaw["RenewStatus"]) } + objectRaw, err = crServiceV2.DescribeInstanceListInstanceEndpoint(d.Id()) + if err != nil && !NotFoundError(err) { + return WrapError(err) + } + + endpoints1Raw, _ := jsonpath.Get("$.Endpoints", objectRaw) + + instanceEndpointsMaps := make([]map[string]interface{}, 0) + if endpoints1Raw != nil { + for _, endpointsChild1Raw := range endpoints1Raw.([]interface{}) { + instanceEndpointsMap := make(map[string]interface{}) + endpointsChild1Raw := endpointsChild1Raw.(map[string]interface{}) + instanceEndpointsMap["enable"] = endpointsChild1Raw["Enable"] + instanceEndpointsMap["endpoint_type"] = endpointsChild1Raw["EndpointType"] + + domains1Raw := endpointsChild1Raw["Domains"] + domainsMaps := make([]map[string]interface{}, 0) + if domains1Raw != nil { + for _, domainsChild1Raw := range domains1Raw.([]interface{}) { + domainsMap := make(map[string]interface{}) + domainsChild1Raw := domainsChild1Raw.(map[string]interface{}) + domainsMap["domain"] = domainsChild1Raw["Domain"] + domainsMap["type"] = domainsChild1Raw["Type"] + + domainsMaps = append(domainsMaps, domainsMap) + } + } + instanceEndpointsMap["domains"] = domainsMaps + instanceEndpointsMaps = append(instanceEndpointsMaps, instanceEndpointsMap) + } + } + if objectRaw["Endpoints"] != nil { + if err := d.Set("instance_endpoints", instanceEndpointsMaps); err != nil { + return err + } + } + d.Set("created_time", d.Get("create_time")) return nil } diff --git a/alicloud/resource_alicloud_cr_ee_instance_test.go b/alicloud/resource_alicloud_cr_ee_instance_test.go index 14dbd90f4cd0..93d3542b991e 100644 --- a/alicloud/resource_alicloud_cr_ee_instance_test.go +++ b/alicloud/resource_alicloud_cr_ee_instance_test.go @@ -324,9 +324,10 @@ func TestAccAliCloudCrInstance_basic7970_modified(t *testing.T) { } var AlicloudCrInstanceMap7970_modified = map[string]string{ - "status": CHECKSET, - "end_time": CHECKSET, - "create_time": CHECKSET, + "status": CHECKSET, + "end_time": CHECKSET, + "create_time": CHECKSET, + "instance_endpoints.#": CHECKSET, } func AlicloudCrInstanceBasicDependence7970_modified(name string) string { diff --git a/alicloud/service_alicloud_cr_v2.go b/alicloud/service_alicloud_cr_v2.go index 8004d12366ad..b45bdfdfb7d4 100644 --- a/alicloud/service_alicloud_cr_v2.go +++ b/alicloud/service_alicloud_cr_v2.go @@ -56,7 +56,7 @@ func (s *CrServiceV2) DescribeCrInstance(id string) (object map[string]interface return response, nil } -func (s *CrServiceV2) DescribeQueryAvailableInstances(id string) (object map[string]interface{}, err error) { +func (s *CrServiceV2) DescribeInstanceQueryAvailableInstances(id string) (object map[string]interface{}, err error) { client := s.client var request map[string]interface{} var response map[string]interface{} @@ -110,6 +110,43 @@ func (s *CrServiceV2) DescribeQueryAvailableInstances(id string) (object map[str return v.([]interface{})[0].(map[string]interface{}), nil } +func (s *CrServiceV2) DescribeInstanceListInstanceEndpoint(id string) (object map[string]interface{}, err error) { + client := s.client + var request map[string]interface{} + var response map[string]interface{} + var query map[string]interface{} + action := "ListInstanceEndpoint" + conn, err := client.NewAcrClient() + if err != nil { + return object, WrapError(err) + } + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["InstanceId"] = id + request["RegionId"] = client.RegionId + + runtime := util.RuntimeOptions{} + runtime.SetAutoretry(true) + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-12-01"), StringPointer("AK"), query, request, &runtime) + + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) + } + + return response, nil +} func (s *CrServiceV2) CrInstanceStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc { return func() (interface{}, string, error) { @@ -140,7 +177,7 @@ func (s *CrServiceV2) CrInstanceStateRefreshFunc(id string, field string, failSt } } -func (s *CrServiceV2) DescribeAsyncInstanceGetInstance(d *schema.ResourceData, res map[string]interface{}) (object map[string]interface{}, err error) { +func (s *CrServiceV2) DescribeAsyncGetInstance(d *schema.ResourceData, res map[string]interface{}) (object map[string]interface{}, err error) { client := s.client id := d.Id() var request map[string]interface{} @@ -181,7 +218,7 @@ func (s *CrServiceV2) DescribeAsyncInstanceGetInstance(d *schema.ResourceData, r func (s *CrServiceV2) DescribeAsyncCrInstanceStateRefreshFunc(d *schema.ResourceData, res map[string]interface{}, field string, failStates []string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - object, err := s.DescribeAsyncInstanceGetInstance(d, res) + object, err := s.DescribeAsyncGetInstance(d, res) if err != nil { if NotFoundError(err) { return object, "", nil diff --git a/website/docs/r/cr_ee_instance.html.markdown b/website/docs/r/cr_ee_instance.html.markdown index d1b43bbe8afe..effa0c0d049e 100644 --- a/website/docs/r/cr_ee_instance.html.markdown +++ b/website/docs/r/cr_ee_instance.html.markdown @@ -18,12 +18,6 @@ For information about Container Registry Enterprise Edition instances and how to Basic Usage -
- ```terraform variable "name" { default = "terraform-example" @@ -48,17 +42,18 @@ resource "alicloud_cr_ee_instance" "default" { The following arguments are supported: * `custom_oss_bucket` - (Optional) Custom OSS Bucket name -* `default_oss_bucket` - (Optional, Available since v1.235.0) Whether to use the default OSS Bucket -* `image_scanner` - (Optional, Available since v1.235.0) Security scan engine +* `default_oss_bucket` - (Optional, Available since v1.235.0) Whether to use the default OSS Bucket. Value: + - `true`: Use the default OSS Bucket. + - `false`: Use a custom OSS Bucket. +* `image_scanner` - (Optional, Available since v1.235.0) The security scan engine used by the Enterprise Edition of Container Image Service. Value: + - `ACR`: Uses the Trivy scan engine provided by default. + - `SAS`: uses the enhanced cloud security scan engine. * `instance_name` - (Required, ForceNew) InstanceName * `instance_type` - (Required) The Value configuration of the Group 1 attribute of Container Mirror Service Enterprise Edition. Valid values: - - Basic: Basic instance - - Standard: Standard instance - - Advanced: Advanced Edition Instance -* `password` - (Optional) Permanent access credentials of the instance + - `Basic`: Basic instance + - `Standard`: Standard instance + - `Advanced`: Advanced Edition Instance +* `password` - (Optional) Login password, 8-32 digits, must contain at least two letters, symbols, or numbers * `payment_type` - (Required, ForceNew) Payment type, value: - Subscription: Prepaid. * `period` - (Optional, Int) Prepaid cycle. The unit is Monthly, please enter an integer multiple of 12 for annual paid products. @@ -87,6 +82,12 @@ The following attributes are exported: * `id` - The ID of the resource supplied above. * `create_time` - The creation time of the resource * `end_time` - Expiration Time +* `instance_endpoints` - (Available since v1.240.0) Instance Network Access Endpoint List + * `domains` - Domain List + * `domain` - Domain + * `type` - Domain Type + * `enable` - enable + * `endpoint_type` - Network Access Endpoint Type * `region_id` - RegionId * `status` - Instance Status