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_express_connect_router_grant_association: change ID fields. #8002

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ func resourceAliCloudExpressConnectRouterGrantAssociationCreate(d *schema.Resour
return WrapError(err)
}
request = make(map[string]interface{})
request["EcrOwnerAliUid"] = d.Get("ecr_owner_ali_uid")
request["InstanceId"] = d.Get("instance_id")
request["InstanceType"] = d.Get("instance_type")
request["InstanceRegionId"] = d.Get("instance_region_id")
request["EcrId"] = d.Get("ecr_id")

request["ClientToken"] = buildClientToken(action)

request["EcrOwnerAliUid"] = d.Get("ecr_owner_ali_uid")
request["InstanceType"] = d.Get("instance_type")
request["CallerType"] = "OTHER"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand All @@ -101,7 +101,7 @@ func resourceAliCloudExpressConnectRouterGrantAssociationCreate(d *schema.Resour
return WrapErrorf(err, DefaultErrorMsg, "alicloud_express_connect_router_grant_association", action, AlibabaCloudSdkGoERROR)
}

d.SetId(fmt.Sprintf("%v:%v:%v", request["EcrId"], request["InstanceId"], request["InstanceRegionId"]))
d.SetId(fmt.Sprintf("%v:%v:%v:%v:%v", request["EcrId"], request["InstanceId"], request["InstanceRegionId"], request["EcrOwnerAliUid"], request["InstanceType"]))

return resourceAliCloudExpressConnectRouterGrantAssociationRead(d, meta)
}
Expand All @@ -120,24 +120,24 @@ func resourceAliCloudExpressConnectRouterGrantAssociationRead(d *schema.Resource
return WrapError(err)
}

if objectRaw["EcrOwnerAliUid"] != nil {
d.Set("ecr_owner_ali_uid", objectRaw["EcrOwnerAliUid"])
}
if objectRaw["NodeType"] != nil {
d.Set("instance_type", objectRaw["NodeType"])
}
if objectRaw["Status"] != nil {
d.Set("status", objectRaw["Status"])
}
if objectRaw["EcrId"] != nil {
d.Set("ecr_id", objectRaw["EcrId"])
}
if objectRaw["EcrOwnerAliUid"] != nil {
d.Set("ecr_owner_ali_uid", objectRaw["EcrOwnerAliUid"])
}
if objectRaw["NodeId"] != nil {
d.Set("instance_id", objectRaw["NodeId"])
}
if objectRaw["NodeRegionId"] != nil {
d.Set("instance_region_id", objectRaw["NodeRegionId"])
}
if objectRaw["NodeType"] != nil {
d.Set("instance_type", objectRaw["NodeType"])
}

return nil
}
Expand All @@ -155,14 +155,14 @@ func resourceAliCloudExpressConnectRouterGrantAssociationDelete(d *schema.Resour
return WrapError(err)
}
request = make(map[string]interface{})
request["EcrOwnerAliUid"] = parts[3]
request["InstanceId"] = parts[1]
request["InstanceType"] = parts[4]
request["InstanceRegionId"] = parts[2]
request["EcrId"] = parts[0]

request["ClientToken"] = buildClientToken(action)

request["EcrOwnerAliUid"] = d.Get("ecr_owner_ali_uid")
request["InstanceType"] = d.Get("instance_type")
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
Expand Down
27 changes: 24 additions & 3 deletions alicloud/service_alicloud_express_connect_router_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@ func (s *ExpressConnectRouterServiceV2) DescribeExpressConnectRouterGrantAssocia
var response map[string]interface{}
var query map[string]interface{}
parts := strings.Split(id, ":")
if len(parts) != 3 {
err = WrapError(fmt.Errorf("invalid Resource Id %s. Expected parts' length %d, got %d", id, 3, len(parts)))
if len(parts) != 5 {
err = WrapError(fmt.Errorf("invalid Resource Id %s. Expected parts' length %d, got %d", id, 5, len(parts)))
}
action := "DescribeInstanceGrantedToExpressConnectRouter"
conn, err := client.NewExpressconnectrouterClient()
Expand All @@ -966,6 +966,7 @@ func (s *ExpressConnectRouterServiceV2) DescribeExpressConnectRouterGrantAssocia
request["EcrId"] = parts[0]
request["InstanceId"] = parts[1]
request["InstanceRegionId"] = parts[2]
request["InstanceType"] = parts[4]

request["ClientToken"] = buildClientToken(action)

Expand Down Expand Up @@ -1000,7 +1001,27 @@ func (s *ExpressConnectRouterServiceV2) DescribeExpressConnectRouterGrantAssocia
return object, WrapErrorf(Error(GetNotFoundMessage("GrantAssociation", id)), NotFoundMsg, response)
}

return v.([]interface{})[0].(map[string]interface{}), nil
result, _ := v.([]interface{})
for _, v := range result {
item := v.(map[string]interface{})
if fmt.Sprint(item["EcrId"]) != parts[0] {
continue
}
if fmt.Sprint(item["EcrOwnerAliUid"]) != parts[3] {
continue
}
if fmt.Sprint(item["NodeId"]) != parts[1] {
continue
}
if fmt.Sprint(item["NodeRegionId"]) != parts[2] {
continue
}
if fmt.Sprint(item["NodeType"]) != parts[4] {
continue
}
return item, nil
}
return object, WrapErrorf(Error(GetNotFoundMessage("GrantAssociation", id)), NotFoundMsg, response)
}

func (s *ExpressConnectRouterServiceV2) ExpressConnectRouterGrantAssociationStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ provider "alicloud" {
}

variable "vpc_id" {
default = "vpc-7qbx5bpq0axxbt9pqnzel"
# You need to modify this value to an existing VPC under your account
default = "vpc-xxx"
}

variable "ecr_owner_uid" {
default = <<EOF
1891593620094065
EOF
# You need to modify this value to ecr owner ali uid
default = "18xxx"
}

variable "ecr_id" {
default = "ecr-0a6p1fk05ji1whedvj"
# You need to modify this value to an existing ecr id
default = "ecr-xxx"
}

variable "region" {
default = "cn-wulanchabu-example-5"
default = "cn-hangzhou"
}


Expand All @@ -71,7 +72,7 @@ The following arguments are supported:
## Attributes Reference

The following attributes are exported:
* `id` - The ID of the resource supplied above.The value is formulated as `<ecr_id>:<instance_id>:<instance_region_id>`.
* `id` - The ID of the resource supplied above.The value is formulated as `<ecr_id>:<instance_id>:<instance_region_id>:<ecr_owner_ali_uid>:<instance_type>`.
* `status` - The status of the resource

## Timeouts
Expand All @@ -85,5 +86,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
Express Connect Router Grant Association can be imported using the id, e.g.

```shell
$ terraform import alicloud_express_connect_router_grant_association.example <ecr_id>:<instance_id>:<instance_region_id>
$ terraform import alicloud_express_connect_router_grant_association.example <ecr_id>:<instance_id>:<instance_region_id>:<ecr_owner_ali_uid>:<instance_type>
```
Loading