Skip to content

Commit

Permalink
resource/alicloud_eip_address: improve document; alicloud_eip_associa…
Browse files Browse the repository at this point in the history
…tion: improve document; alicloud_eip_segment_address: add new attribute zone, resource_group_id and segment_address_name.
  • Loading branch information
ChenHanZhang committed Jun 22, 2024
1 parent 87bd0e8 commit b910cd9
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 245 deletions.
106 changes: 76 additions & 30 deletions alicloud/resource_alicloud_eip_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ func resourceAliCloudEipAddress() *schema.Resource {
"allocation_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"auto_pay": {
Type: schema.TypeBool,
Optional: true,
},
"bandwidth": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: StringLenBetween(1, 200),
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"create_time": {
Type: schema.TypeString,
Expand Down Expand Up @@ -318,26 +319,61 @@ func resourceAliCloudEipAddressRead(d *schema.ResourceData, meta interface{}) er
return WrapError(err)
}

d.Set("address_name", objectRaw["Name"])
if eipBandwidth, ok := objectRaw["EipBandwidth"]; ok {
d.Set("bandwidth", eipBandwidth)
} else {
d.Set("bandwidth", objectRaw["Bandwidth"])
}
d.Set("create_time", objectRaw["AllocationTime"])
d.Set("deletion_protection", objectRaw["DeletionProtection"])
d.Set("description", objectRaw["Description"])
d.Set("high_definition_monitor_log_status", objectRaw["HDMonitorStatus"])
d.Set("internet_charge_type", objectRaw["InternetChargeType"])
d.Set("ip_address", objectRaw["IpAddress"])
d.Set("isp", objectRaw["ISP"])
d.Set("mode", objectRaw["Mode"])
d.Set("netmode", objectRaw["Netmode"])
d.Set("payment_type", convertEipAddressEipAddressesEipAddressChargeTypeResponse(objectRaw["ChargeType"]))
d.Set("public_ip_address_pool_id", objectRaw["PublicIpAddressPoolId"])
d.Set("resource_group_id", objectRaw["ResourceGroupId"])
d.Set("status", objectRaw["Status"])
d.Set("zone", objectRaw["Zone"])
if objectRaw["Name"] != nil {
d.Set("address_name", objectRaw["Name"])
}
if objectRaw["Bandwidth"] != nil || objectRaw["EipBandwidth"] != nil {
if eipBandwidth, ok := objectRaw["EipBandwidth"]; ok {
d.Set("bandwidth", eipBandwidth)
} else {
d.Set("bandwidth", objectRaw["Bandwidth"])
}
}
if objectRaw["AllocationTime"] != nil {
d.Set("create_time", objectRaw["AllocationTime"])
}
if objectRaw["DeletionProtection"] != nil {
d.Set("deletion_protection", objectRaw["DeletionProtection"])
}
if objectRaw["Description"] != nil {
d.Set("description", objectRaw["Description"])
}
if objectRaw["HDMonitorStatus"] != nil {
d.Set("high_definition_monitor_log_status", objectRaw["HDMonitorStatus"])
}
if objectRaw["InternetChargeType"] != nil {
d.Set("internet_charge_type", objectRaw["InternetChargeType"])
}
if objectRaw["IpAddress"] != nil {
d.Set("ip_address", objectRaw["IpAddress"])
}
if objectRaw["ISP"] != nil {
d.Set("isp", objectRaw["ISP"])
}
if objectRaw["Mode"] != nil {
d.Set("mode", objectRaw["Mode"])
}
if objectRaw["Netmode"] != nil {
d.Set("netmode", objectRaw["Netmode"])
}
if convertEipAddressEipAddressesEipAddressChargeTypeResponse(objectRaw["ChargeType"]) != nil {
d.Set("payment_type", convertEipAddressEipAddressesEipAddressChargeTypeResponse(objectRaw["ChargeType"]))
}
if objectRaw["PublicIpAddressPoolId"] != nil {
d.Set("public_ip_address_pool_id", objectRaw["PublicIpAddressPoolId"])
}
if objectRaw["ResourceGroupId"] != nil {
d.Set("resource_group_id", objectRaw["ResourceGroupId"])
}
if objectRaw["Status"] != nil {
d.Set("status", objectRaw["Status"])
}
if objectRaw["Zone"] != nil {
d.Set("zone", objectRaw["Zone"])
}
if objectRaw["AllocationId"] != nil {
d.Set("allocation_id", objectRaw["AllocationId"])
}

securityProtectionType1Raw, _ := jsonpath.Get("$.SecurityProtectionTypes.SecurityProtectionType", objectRaw)
d.Set("security_protection_types", securityProtectionType1Raw)
Expand All @@ -352,11 +388,20 @@ func resourceAliCloudEipAddressRead(d *schema.ResourceData, meta interface{}) er
return WrapError(err)
}

d.Set("log_project", objectRaw["LogProject"])
d.Set("log_store", objectRaw["LogStore"])
if objectRaw["LogProject"] != nil {
d.Set("log_project", objectRaw["LogProject"])
}
if objectRaw["LogStore"] != nil {
d.Set("log_store", objectRaw["LogStore"])
}
if objectRaw["InstanceId"] != nil {
d.Set("allocation_id", objectRaw["InstanceId"])
}

}

d.Set("allocation_id", d.Id())

d.Set("name", d.Get("address_name"))
d.Set("instance_charge_type", objectRaw["ChargeType"])
return nil
Expand Down Expand Up @@ -594,11 +639,12 @@ func resourceAliCloudEipAddressUpdate(d *schema.ResourceData, meta interface{})

func resourceAliCloudEipAddressDelete(d *schema.ResourceData, meta interface{}) error {

if d.Get("payment_type").(string) == "Subscription" || d.Get("instance_charge_type").(string) == "Prepaid" {
log.Printf("[WARN] Cannot destroy Subscription resource: alicloud_eip_address. Terraform will remove this resource from the state file, however resources may remain.")
return nil
if v, ok := d.GetOk("payment_type"); ok || d.Get("instance_charge_type").(string) == "Prepaid" {
if v == "Subscription" {
log.Printf("[WARN] Cannot destroy resource alicloud_eip_address which payment_type valued Subscription. Terraform will remove this resource from the state file, however resources may remain.")
return nil
}
}

client := meta.(*connectivity.AliyunClient)
action := "ReleaseEipAddress"
var request map[string]interface{}
Expand Down
2 changes: 2 additions & 0 deletions alicloud/resource_alicloud_eip_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ func TestAccAliCloudEIPAddress_basic13(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithTime(t, []int{1})
testAccPreCheckWithRegions(t, true, connectivity.VpcDhcpOptionsSetSupportRegions)
},
IDRefreshName: resourceId,
Expand Down Expand Up @@ -978,6 +979,7 @@ func TestAccAliCloudEIPAddress_basic9_ip(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithTime(t, []int{1})
testAccPreCheckWithRegions(t, true, connectivity.EipAddressZoneSupportRegions)
},
IDRefreshName: resourceId,
Expand Down
Loading

0 comments on commit b910cd9

Please sign in to comment.