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

update kms instance policies #5346

Merged
merged 5 commits into from
May 16, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ require (
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.0.4
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
github.com/IBM/keyprotect-go-client v0.14.0
github.com/IBM/networking-go-sdk v0.46.1
github.com/IBM/logs-go-sdk v0.1.1
github.com/IBM/platform-services-go-sdk v0.62.11
github.com/IBM/project-go-sdk v0.3.0
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
Expand Down Expand Up @@ -64,6 +63,7 @@ require (
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20240423071914-9e96525baef4
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/logs-go-sdk v0.1.1
github.com/IBM/mqcloud-go-sdk v0.0.4
github.com/IBM/sarama v1.41.2
github.com/IBM/vmware-go-sdk v0.1.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYt
github.com/IBM/keyprotect-go-client v0.5.1/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
github.com/IBM/keyprotect-go-client v0.12.2 h1:Cjxcqin9Pl0xz3MnxdiVd4v/eIa79xL3hQpSbwOr/DQ=
github.com/IBM/keyprotect-go-client v0.12.2/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM=
github.com/IBM/keyprotect-go-client v0.14.0 h1:GqgK3BdczA/w7+B1RxEPLya0w9S/ZXi5YWKAxdW8vHQ=
github.com/IBM/keyprotect-go-client v0.14.0/go.mod h1:cAt714Vnwnd03mmkBHHSJlDNRVthdRmJB6RePd4/B8Q=
github.com/IBM/logs-go-sdk v0.1.1 h1:aiVnKHJzYcsHvQY58vLB7QbUV/kXcWTpCPqRKC2QS0A=
github.com/IBM/logs-go-sdk v0.1.1/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
github.com/IBM/mqcloud-go-sdk v0.0.4 h1:gqMpoU5a0qJ0GETG4PQrkgeEEoaQLvbxRJnEe6ytvC4=
Expand Down
25 changes: 19 additions & 6 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3157,12 +3157,25 @@ func FlattenInstancePolicy(policyType string, policies []kp.InstancePolicy) []ma
metricsMap = append(metricsMap, policyInstance)
}
if policy.PolicyType == "keyCreateImportAccess" {
policyInstance["enabled"] = policy.PolicyData.Enabled
policyInstance["create_root_key"] = policy.PolicyData.Attributes.CreateRootKey
policyInstance["create_standard_key"] = policy.PolicyData.Attributes.CreateStandardKey
policyInstance["import_root_key"] = policy.PolicyData.Attributes.ImportRootKey
policyInstance["import_standard_key"] = policy.PolicyData.Attributes.ImportStandardKey
policyInstance["enforce_token"] = policy.PolicyData.Attributes.EnforceToken
if policy.PolicyData.Enabled != nil {
policyInstance["enabled"] = *policy.PolicyData.Enabled
}
if policy.PolicyData.Attributes.CreateRootKey != nil {
policyInstance["create_root_key"] = *policy.PolicyData.Attributes.CreateRootKey
}
if policy.PolicyData.Attributes.CreateStandardKey != nil {
policyInstance["create_standard_key"] = *policy.PolicyData.Attributes.CreateStandardKey
}
if policy.PolicyData.Attributes.ImportRootKey != nil {
policyInstance["import_root_key"] = *policy.PolicyData.Attributes.ImportRootKey
}
if policy.PolicyData.Attributes.ImportStandardKey != nil {
policyInstance["import_standard_key"] = *policy.PolicyData.Attributes.ImportStandardKey
}
if policy.PolicyData.Attributes.EnforceToken != nil {
policyInstance["enforce_token"] = *policy.PolicyData.Attributes.EnforceToken
}

keyCreateImportAccessMap = append(keyCreateImportAccessMap, policyInstance)
}
}
Expand Down
31 changes: 24 additions & 7 deletions ibm/service/kms/resource_ibm_kms_instance_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,30 @@ func policyCreateOrUpdate(context context.Context, d *schema.ResourceData, kpAPI
if kciaip, ok := d.GetOk("key_create_import_access"); ok {
kciaipList := kciaip.([]interface{})
if len(kciaipList) != 0 {
mulPolicy.KeyCreateImportAccess = &kp.KeyCreateImportAccessInstancePolicy{
Enabled: kciaipList[0].(map[string]interface{})["enabled"].(bool),
CreateRootKey: kciaipList[0].(map[string]interface{})["create_root_key"].(bool),
CreateStandardKey: kciaipList[0].(map[string]interface{})["create_standard_key"].(bool),
ImportRootKey: kciaipList[0].(map[string]interface{})["import_root_key"].(bool),
ImportStandardKey: kciaipList[0].(map[string]interface{})["import_standard_key"].(bool),
EnforceToken: kciaipList[0].(map[string]interface{})["enforce_token"].(bool),
enabled := kciaipList[0].(map[string]interface{})["enabled"].(bool)
create_root_key := kciaipList[0].(map[string]interface{})["create_root_key"].(bool)
create_standard_key := kciaipList[0].(map[string]interface{})["create_standard_key"].(bool)
import_root_key := kciaipList[0].(map[string]interface{})["import_root_key"].(bool)
import_standard_key := kciaipList[0].(map[string]interface{})["import_standard_key"].(bool)
enforce_token := kciaipList[0].(map[string]interface{})["enforce_token"].(bool)

// we must make sure not to attempt any updates on attributes when enabled is false or face input validation errors
if enabled {
mulPolicy.KeyCreateImportAccess = &kp.KeyCreateImportAccessInstancePolicy{
Enabled: enabled,
Attributes: &kp.KeyCreateImportAccessInstancePolicyAttributes{
CreateRootKey: &create_root_key,
CreateStandardKey: &create_standard_key,
ImportRootKey: &import_root_key,
ImportStandardKey: &import_standard_key,
EnforceToken: &enforce_token,
},
}
} else {
mulPolicy.KeyCreateImportAccess = &kp.KeyCreateImportAccessInstancePolicy{
Enabled: enabled,
Attributes: nil,
}
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions website/docs/r/kms_instance_policies.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,30 @@ resource "ibm_kms_instance_policies" "instance_policy" {
enabled = true
}
key_create_import_access {
enable = true
enabled = true
}
}

```

**NOTE**
- To create an instance policy, atleast one of the policy block as mentioned in the argument section is mandatory.
- When setting `enabled=false`, you must not specify any other attributes for that policy. The below is an example of an invalid setting

```terraform
key_create_import_access {
enabled = false
import_root_key = false
}
```

The extra attributes will be ignored and will not be updated, this can also cause state drift. Users are advised to only use the `enabled` attribute when disabling a policy

```terraform
key_create_import_access {
enabled = false
}
```


- Policies `allowedIP` and `allowedNetwork` are not supported by instance_policies resource, and can be set using Context Based Restrictions (CBR).
## Argument reference
Expand Down
Loading