Skip to content

Commit 7686662

Browse files
committed
resource/alicloud_kms_instance: support set log and log_storage for PayAsYouGo instance.
1 parent 8e5dd23 commit 7686662

File tree

3 files changed

+107
-25
lines changed

3 files changed

+107
-25
lines changed

alicloud/resource_alicloud_kms_instance.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
21
package alicloud
32

43
import (
@@ -91,24 +90,12 @@ func resourceAliCloudKmsInstance() *schema.Resource {
9190
Optional: true,
9291
Computed: true,
9392
ValidateFunc: StringInSlice([]string{"0", "1"}, false),
94-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
95-
if v, ok := d.GetOk("payment_type"); ok && v.(string) == "PayAsYouGo" {
96-
return true
97-
}
98-
return false
99-
},
10093
},
10194
"log_storage": {
10295
Type: schema.TypeInt,
10396
Optional: true,
10497
Computed: true,
10598
ValidateFunc: IntBetween(0, 500000),
106-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
107-
if v, ok := d.GetOk("payment_type"); ok && v.(string) == "PayAsYouGo" {
108-
return true
109-
}
110-
return false
111-
},
11299
},
113100
"payment_type": {
114101
Type: schema.TypeString,
@@ -493,16 +480,7 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{})
493480
update := false
494481
d.Partial(true)
495482

496-
kmsServiceV2 := KmsServiceV2{client}
497-
objectRaw, _ := kmsServiceV2.DescribeKmsInstance(d.Id())
498-
499483
var err error
500-
objectRaw, _ = kmsServiceV2.DescribeKmsInstance(d.Id())
501-
enableModifyInstance1 := false
502-
checkValue00 := convertKmsInstanceKmsInstanceChargeTypeResponse(objectRaw["ChargeType"])
503-
if checkValue00 == "Subscription" {
504-
enableModifyInstance1 = true
505-
}
506484
action := "ModifyInstance"
507485
request = make(map[string]interface{})
508486
query = make(map[string]interface{})
@@ -577,7 +555,7 @@ func resourceAliCloudKmsInstanceUpdate(d *schema.ResourceData, meta interface{})
577555
request["ProductType"] = "kms_ppi_public_intl"
578556
}
579557
}
580-
if update && enableModifyInstance1 {
558+
if update {
581559
wait := incrementalWait(3*time.Second, 5*time.Second)
582560
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
583561
response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint)

alicloud/resource_alicloud_kms_instance_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,4 +1152,108 @@ func TestAccAliCloudKmsInstance_basic5405_twin(t *testing.T) {
11521152
})
11531153
}
11541154

1155+
func TestAccAliCloudKmsInstance_postpaid_log_enabled(t *testing.T) {
1156+
var v map[string]interface{}
1157+
resourceId := "alicloud_kms_instance.default"
1158+
ra := resourceAttrInit(resourceId, AlicloudKmsInstanceMapLogEnabled)
1159+
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
1160+
return &KmsServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
1161+
}, "DescribeKmsInstance")
1162+
rac := resourceAttrCheckInit(rc, ra)
1163+
testAccCheck := rac.resourceAttrMapUpdateSet()
1164+
rand := acctest.RandIntRange(10000, 99999)
1165+
name := fmt.Sprintf("tf-testacc%skmsinstance%d", defaultRegionToTest, rand)
1166+
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudKmsInstanceBasicDependenceLogEnabled)
1167+
resource.Test(t, resource.TestCase{
1168+
PreCheck: func() {
1169+
testAccPreCheck(t)
1170+
testAccPreCheckWithAccountSiteType(t, DomesticSite)
1171+
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-wulanchabu"})
1172+
},
1173+
IDRefreshName: resourceId,
1174+
Providers: testAccProviders,
1175+
CheckDestroy: rac.checkResourceDestroy(),
1176+
Steps: []resource.TestStep{
1177+
{
1178+
Config: testAccConfig(map[string]interface{}{
1179+
"payment_type": "PayAsYouGo",
1180+
"product_version": "3",
1181+
"log": "1",
1182+
"log_storage": "1000",
1183+
"vpc_id": "${alicloud_vpc.vpc-amp-instance-example.id}",
1184+
"zone_ids": []string{
1185+
"${alicloud_vswitch.vswitcha.zone_id}", "${alicloud_vswitch.vswitchb.zone_id}"},
1186+
"vswitch_ids": []string{
1187+
"${alicloud_vswitch.vswitcha.id}"},
1188+
"force_delete_without_backup": "true",
1189+
}),
1190+
Check: resource.ComposeTestCheckFunc(
1191+
testAccCheck(map[string]string{
1192+
"payment_type": "PayAsYouGo",
1193+
"product_version": "3",
1194+
"log": "1",
1195+
"log_storage": "1000",
1196+
"vpc_id": CHECKSET,
1197+
"zone_ids.#": "2",
1198+
"vswitch_ids.#": "1",
1199+
}),
1200+
),
1201+
},
1202+
{
1203+
Config: testAccConfig(map[string]interface{}{
1204+
"log_storage": "2000",
1205+
}),
1206+
Check: resource.ComposeTestCheckFunc(
1207+
testAccCheck(map[string]string{
1208+
"log_storage": "2000",
1209+
}),
1210+
),
1211+
},
1212+
{
1213+
ResourceName: resourceId,
1214+
ImportState: true,
1215+
ImportStateVerify: true,
1216+
ImportStateVerifyIgnore: []string{"force_delete_without_backup", "log_storage"},
1217+
},
1218+
},
1219+
})
1220+
}
1221+
1222+
var AlicloudKmsInstanceMapLogEnabled = map[string]string{
1223+
"status": CHECKSET,
1224+
"create_time": CHECKSET,
1225+
"end_date": CHECKSET,
1226+
"instance_name": CHECKSET,
1227+
"ca_certificate_chain_pem": CHECKSET,
1228+
"payment_type": "PayAsYouGo",
1229+
"product_version": "3",
1230+
"log": "1",
1231+
"log_storage": "1000",
1232+
}
1233+
1234+
func AlicloudKmsInstanceBasicDependenceLogEnabled(name string) string {
1235+
return fmt.Sprintf(`
1236+
variable "name" {
1237+
default = "%s"
1238+
}
1239+
1240+
resource "alicloud_vpc" "vpc-amp-instance-example" {
1241+
cidr_block = "172.16.0.0/12"
1242+
vpc_name = var.name
1243+
}
1244+
1245+
resource "alicloud_vswitch" "vswitcha" {
1246+
vpc_id = alicloud_vpc.vpc-amp-instance-example.id
1247+
zone_id = "cn-wulanchabu-a"
1248+
cidr_block = "172.16.1.0/24"
1249+
}
1250+
1251+
resource "alicloud_vswitch" "vswitchb" {
1252+
vpc_id = alicloud_vpc.vpc-amp-instance-example.id
1253+
zone_id = "cn-wulanchabu-b"
1254+
cidr_block = "172.16.2.0/24"
1255+
}
1256+
`, name)
1257+
}
1258+
11551259
// Test Kms Instance. <<< Resource test cases, automatically generated.

website/docs/r/kms_instance.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ The following arguments are supported:
229229

230230
* `instance_name` - (Optional, Computed) The name of the resource
231231
* `key_num` - (Optional, Int) Maximum number of stored keys. The attribute is valid when the attribute `payment_type` is `Subscription`.
232-
* `log` - (Optional, Computed) Instance Audit Log Switch.
233-
* `log_storage` - (Optional, Computed, Int) Instance log capacity.
232+
* `log` - (Optional, Computed) Instance Audit Log Switch. This attribute was limited to Subscription (prepaid) payment type before v1.264.0. As of v1.264.0, it is also supported for PayAsYouGo (postpaid) instances.
233+
* `log_storage` - (Optional, Computed, Int) Instance log capacity. This attribute was limited to Subscription (prepaid) payment type before v1.264.0. As of v1.264.0, it is also supported for PayAsYouGo (postpaid) instances.
234234
* `payment_type` - (Optional, ForceNew, Computed) The billing method. Valid values:
235235

236236
- Subscription: the subscription billing method.

0 commit comments

Comments
 (0)