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_log_store: fix attribute encrypt_conf.user_cmk_info while empty. #6843

Merged
merged 1 commit into from
Jan 9, 2024
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
58 changes: 32 additions & 26 deletions alicloud/resource_alicloud_log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,23 @@ func resourceAliCloudSlsLogStoreCreate(d *schema.ResourceData, meta interface{})
if nodeNative1 != "" {
objectDataLocalMap["encrypt_type"] = nodeNative1
}
user_cmk_info := make(map[string]interface{})
nodeNative2, _ := jsonpath.Get("$[0].user_cmk_info[0].cmk_key_id", d.Get("encrypt_conf"))
if nodeNative2 != "" {
user_cmk_info["cmk_key_id"] = nodeNative2
}
nodeNative3, _ := jsonpath.Get("$[0].user_cmk_info[0].arn", d.Get("encrypt_conf"))
if nodeNative3 != "" {
user_cmk_info["arn"] = nodeNative3
}
nodeNative4, _ := jsonpath.Get("$[0].user_cmk_info[0].region_id", d.Get("encrypt_conf"))
if nodeNative4 != "" {
user_cmk_info["region_id"] = nodeNative4
user_cmk_info_map, _ := jsonpath.Get("$[0].user_cmk_info[0]", v)
if !IsNil(user_cmk_info_map) {
user_cmk_info := make(map[string]interface{})
nodeNative2, _ := jsonpath.Get("$[0].user_cmk_info[0].cmk_key_id", d.Get("encrypt_conf"))
if nodeNative2 != "" {
user_cmk_info["cmk_key_id"] = nodeNative2
}
nodeNative3, _ := jsonpath.Get("$[0].user_cmk_info[0].arn", d.Get("encrypt_conf"))
if nodeNative3 != "" {
user_cmk_info["arn"] = nodeNative3
}
nodeNative4, _ := jsonpath.Get("$[0].user_cmk_info[0].region_id", d.Get("encrypt_conf"))
if nodeNative4 != "" {
user_cmk_info["region_id"] = nodeNative4
}
objectDataLocalMap["user_cmk_info"] = user_cmk_info
}
objectDataLocalMap["user_cmk_info"] = user_cmk_info
request["encrypt_conf"] = objectDataLocalMap
}

Expand Down Expand Up @@ -481,20 +484,23 @@ func resourceAliCloudSlsLogStoreUpdate(d *schema.ResourceData, meta interface{})
if nodeNative1 != "" {
objectDataLocalMap["encrypt_type"] = nodeNative1
}
user_cmk_info := make(map[string]interface{})
nodeNative2, _ := jsonpath.Get("$[0].user_cmk_info[0].cmk_key_id", v)
if nodeNative2 != "" {
user_cmk_info["cmk_key_id"] = nodeNative2
}
nodeNative3, _ := jsonpath.Get("$[0].user_cmk_info[0].arn", v)
if nodeNative3 != "" {
user_cmk_info["arn"] = nodeNative3
}
nodeNative4, _ := jsonpath.Get("$[0].user_cmk_info[0].region_id", v)
if nodeNative4 != "" {
user_cmk_info["region_id"] = nodeNative4
user_cmk_info_map, _ := jsonpath.Get("$[0].user_cmk_info[0]", v)
if !IsNil(user_cmk_info_map) {
user_cmk_info := make(map[string]interface{})
nodeNative2, _ := jsonpath.Get("$[0].user_cmk_info[0].cmk_key_id", v)
if nodeNative2 != "" {
user_cmk_info["cmk_key_id"] = nodeNative2
}
nodeNative3, _ := jsonpath.Get("$[0].user_cmk_info[0].arn", v)
if nodeNative3 != "" {
user_cmk_info["arn"] = nodeNative3
}
nodeNative4, _ := jsonpath.Get("$[0].user_cmk_info[0].region_id", v)
if nodeNative4 != "" {
user_cmk_info["region_id"] = nodeNative4
}
objectDataLocalMap["user_cmk_info"] = user_cmk_info
}
objectDataLocalMap["user_cmk_info"] = user_cmk_info
request["encrypt_conf"] = objectDataLocalMap
}

Expand Down
132 changes: 132 additions & 0 deletions alicloud/resource_alicloud_log_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,138 @@ func TestAccAliCloudLogStore_create_with_encrypt(t *testing.T) {
})
}

func TestAccAliCloudLogStore_create_with_encrypt_bugfix(t *testing.T) {
var v *sls.LogStore
resourceId := "alicloud_log_store.default"
ra := resourceAttrInit(resourceId, logStoreMap)
serviceFunc := func() interface{} {
return &LogService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}
rc := resourceCheckInit(resourceId, &v, serviceFunc)
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testacc-log-store-%d", rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceLogStoreConfigDependenceWithEncrypt)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"name": name,
"project": "${alicloud_log_project.foo.name}",
"shard_count": "1",
"encrypt_conf": []map[string]interface{}{
{
"enable": "true",
"encrypt_type": "default",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"name": name,
"project": name,
"shard_count": "1",
"encrypt_conf.#": "1",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccConfig(map[string]interface{}{
"encrypt_conf": []map[string]interface{}{
{
"enable": "true",
"encrypt_type": "m4",
"user_cmk_info": []map[string]string{
{
"cmk_key_id": "${alicloud_kms_key.key.id}",
"arn": "acs:ram::${data.alicloud_account.default.id}:role/aliyunlogdefaultrole",
"region_id": os.Getenv("ALICLOUD_REGION"),
},
},
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"encrypt_conf.#": "1",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"encrypt_conf": []map[string]interface{}{
{
"enable": "false",
"encrypt_type": "default",
"user_cmk_info": []map[string]string{
{
"cmk_key_id": "${alicloud_kms_key.key.id}",
"arn": "acs:ram::${data.alicloud_account.default.id}:role/aliyunlogdefaultrole",
"region_id": os.Getenv("ALICLOUD_REGION"),
},
},
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"encrypt_conf.#": "1",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"encrypt_conf": []map[string]interface{}{
{
"enable": "true",
"encrypt_type": "default",
"user_cmk_info": []map[string]string{
{
"cmk_key_id": "${alicloud_kms_key.key.id}",
"arn": "acs:ram::${data.alicloud_account.default.id}:role/aliyunlogdefaultrole",
"region_id": os.Getenv("ALICLOUD_REGION"),
},
},
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"encrypt_conf.#": "1",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"encrypt_conf": []map[string]interface{}{
{
"enable": "false",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"encrypt_conf.#": "1",
}),
),
},
},
})
}

func TestAccAliCloudLogStore_create_with_encrypt_enable(t *testing.T) {
var v *sls.LogStore
resourceId := "alicloud_log_store.default"
Expand Down
Loading