Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_cr_ee_instance: add new attribute instance_endpoints. #8040

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions alicloud/resource_alicloud_cr_ee_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions alicloud/resource_alicloud_cr_ee_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 40 additions & 3 deletions alicloud/service_alicloud_cr_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions website/docs/r/cr_ee_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ For information about Container Registry Enterprise Edition instances and how to

Basic Usage

<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
<a href="https://api.aliyun.com/terraform?resource=alicloud_cr_ee_instance&exampleId=22381149-4704-d4bc-dbb5-cafc5c4bdc8e6d63f70f&activeTab=example&spm=docs.r.cr_ee_instance.0.2238114947&intl_lang=EN_US" target="_blank">
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
</a>
</div></div>

```terraform
variable "name" {
default = "terraform-example"
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down
Loading