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

privatezone接入 #604

Merged
merged 1 commit into from
Aug 22, 2018
Merged

privatezone接入 #604

merged 1 commit into from
Aug 22, 2018

Conversation

forcoder
Copy link

@forcoder forcoder commented Aug 15, 2018

privatezone接入

@CLAassistant
Copy link

CLAassistant commented Aug 15, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


qiaozhou seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


qiaozhou seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

func (c *Config) pvtzConn() (*pvtz.Client, error) {
return pvtz.NewClientWithAccessKey(c.RegionId, c.AccessKey, c.SecretKey)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在terraform要支持专有云,所以在build client之前要获取用户指定的endpoint;其次,使用NewClientWithOptions来构造新的client

Optional: true,
},

"pvtz_zones": &schema.Schema{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接使用zones就好,不用“pvtz_zones”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是要和region以及zones区分开来,要不会混淆的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会混淆的,用户在引用是是通过data.alicloud_pvtz_zones.xxx.zones.0.id来引用的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外,文件data source的文件名应该改为data_source_alicloud_pvtz_zones.go

"zone_name": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改zone_id为id,zone_name 为name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zone_id之类不用和openapi的统一对齐吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要,如果要和API对其,就没发看了,现在咱们的API都存在很多不规范,现在我所在的团队正太规范化。另外,terraform内部保证对其就好了

Type: schema.TypeString,
Computed: true,
},
"update_timestamp": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只保留create_time和update_time就好,去掉create_timestamp和update_timestamp,另外,修改create_time为creation_time

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不用和openapi返回结果对齐是吧?

var pvtzZones []pvtz.Zone
pvtzZoneBindVpcs := make(map[string][]map[string]interface{})

for true {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

93行,直接使用for { 就好了

request := pvtz.CreateDescribeZoneRecordsRequest()
_, zoneId, rr, _ := getRecordIdAndZoneIdAndRr(d, meta)
request.ZoneId = zoneId
request.Keyword = rr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我认为zoneID和recordId就可以确定一个record

Copy link
Author

@forcoder forcoder Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recordId就可以直接确认一个record,但是他没有根据recordId查询record详情的接口,所以需要根据zoneId+rr来查询

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方不一定要查询到唯一的一个record,根据zoneId查询到一组record之后,可以根据recordId进行过滤,这样可以省去rr


request := pvtz.CreateDeleteZoneRecordRequest()
recordIdStr, zoneId, rr, _ := getRecordIdAndZoneIdAndRr(d, meta)
recordId, _ := strconv.Atoi(recordIdStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

208行如果有报错,要及时报出来

if len(parts) != 3 {
return "", "", "", fmt.Errorf("invalid resource id")
}
return parts[0], parts[1], parts[2], nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRecordIdAndZoneIdAndRr 和 splitRecordIdAndZoneIdAndRr完全可以合并成一个方法

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为我有场景不是直接使用getRecordIdAndZoneIdAndRr,而是需要使用splitRecordIdAndZoneIdAndRr,所以拆分成两个方法

return fmt.Errorf("No Record ID is set")
}
recordIdStr, zoneId, rr, _ := splitRecordIdAndZoneIdAndRr(rs.Primary.ID)
recordId, err := strconv.Atoi(recordIdStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

106行,有错要先报错

response, err := conn.DescribeZoneInfo(request)
if err != nil {
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以参考其他service,在查询后构造NotFoundError,比如ZoneNotExists可以放在15行

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能给个具体的参考产品?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

任何一个都行,比如vpc

@forcoder forcoder force-pushed the master branch 2 times, most recently from 29acb65 to 7f5858e Compare August 21, 2018 01:24
}
}

d.Partial(false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

115行可以删掉了

ForceNew: true,
},
"vpc_ids": &schema.Schema{
Type: schema.TypeList,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vpc_ids的类型最好申明为set,否则当vpc_ids内的顺序改变时,该资源会出现diff

request := pvtz.CreateDescribeZoneRecordsRequest()
_, zoneId, rr, _ := getRecordIdAndZoneIdAndRr(d, meta)
request.ZoneId = zoneId
request.Keyword = rr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方不一定要查询到唯一的一个record,根据zoneId查询到一组record之后,可以根据recordId进行过滤,这样可以省去rr

}

if _, err := client.DescribePvtzZoneInfo(d.Id()); err != nil {
if NotFoundError(err) || IsExceptedError(err, ZoneNotExists) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

135行直接判断NotFoundError(err)就够了,因为DescribePvtzZoneInfo中应对IsExceptedError(err, ZoneNotExists)进行了处理

Provides a list of Private Zone Records which owned by an Alicloud account.
---

# alicloud\_pvtz_zone_records
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第9行修改为:alicloud_pvtz_zone_records
下同


The following attributes are exported:

* `record_id` - The ID of the Private Zone Record.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

49行我觉得应该是id,不是record_id


* `zone_id` - (Required, Forces new resource) The name of the Private Zone Record.
* `vpc_ids` - (Required) The id List of the VPC, for example:["vpc-1","vpc-2"].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

出参中有一个id,要说明


The following attributes are exported:

* `record_id` - ID of the Private Zone Record.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是ID,部署record_id 吧

@@ -1196,6 +1196,17 @@ func validateNatGatewaySpec(v interface{}, k string) (ws []string, errors []erro
return
}

func validatePrivateZoneRecordPriority(v interface{}, k string) (ws []string, errors []error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数完全可以用validateIntegerInRange替换掉

func (c *Config) pvtzConn() (*pvtz.Client, error) {
endpoint := LoadEndpoint(c.RegionId, PVTZCode)
if endpoint != "" {
endpoints.AddEndpointMapping(c.RegionId, string(PVTZCode), endpoint)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然 private zone是中心化的产品,那么就加一条逻辑吧:当endpoint为空时,endpoint为:pvtz.aliyuncs.com

return fmt.Errorf("bindZoneVpc error:%#v", err)
}

d.SetId(args.ZoneId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

83行就不用再set id了

}

if _, err := client.DescribePvtzZoneInfo(d.Id()); err != nil {
if NotFoundError(err) || IsExceptedError(err, ZoneNotExists) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

136如果是检查ZoneNotExists,有NotFoundError就够了

@@ -85,6 +85,12 @@
<li<%= sidebar_current("docs-alicloud-datasource-ram-users") %>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor的变化也要提交上来

@xiaozhu36 xiaozhu36 merged commit d8e8737 into alibaba:master Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants