-
Notifications
You must be signed in to change notification settings - Fork 118
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
privatezone接入 #604
Conversation
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
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. |
alicloud/config.go
Outdated
func (c *Config) pvtzConn() (*pvtz.Client, error) { | ||
return pvtz.NewClientWithAccessKey(c.RegionId, c.AccessKey, c.SecretKey) | ||
} | ||
|
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接使用zones就好,不用“pvtz_zones”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是要和region以及zones区分开来,要不会混淆的
There was a problem hiding this comment.
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来引用的
There was a problem hiding this comment.
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, | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zone_id之类不用和openapi的统一对齐吗?
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我认为zoneID和recordId就可以确定一个record
There was a problem hiding this comment.
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来查询
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getRecordIdAndZoneIdAndRr 和 splitRecordIdAndZoneIdAndRr完全可以合并成一个方法
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
106行,有错要先报错
alicloud/service_alicloud_pvtz.go
Outdated
response, err := conn.DescribeZoneInfo(request) | ||
if err != nil { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以参考其他service,在查询后构造NotFoundError,比如ZoneNotExists可以放在15行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能给个具体的参考产品?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
任何一个都行,比如vpc
29acb65
to
7f5858e
Compare
} | ||
} | ||
|
||
d.Partial(false) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"]. | ||
|
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是ID,部署record_id 吧
alicloud/validators.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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") %>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vendor的变化也要提交上来
privatezone接入