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

S2S documentation note for ibm_kms_key and minor linting fixes #5529

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion ibm/service/kms/data_source_ibm_kms_key_rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func dataSourceIBMKMSKeyRingsRead(d *schema.ResourceData, meta interface{}) erro
if err != nil || keys == nil {
return fmt.Errorf("[ERROR] Get Key Rings failed with error: %s", err)
}
if keys == nil || keys.KeyRings == nil || len(keys.KeyRings) == 0 {
if keys.KeyRings == nil || len(keys.KeyRings) == 0 {
return fmt.Errorf("[ERROR] No key Rings in instance %s", instanceID)
}

Expand Down
8 changes: 4 additions & 4 deletions ibm/service/kms/data_source_ibm_kms_kmip_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ func dataSourceIBMKMSKmipAdapterBaseSchema() map[string]*schema.Schema {
Computed: true,
Description: "The data specific to the KMIP Adapter profile",
},
"created_by": &schema.Schema{
"created_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that created the adapter.",
},
"created_at": &schema.Schema{
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was created. The date format follows RFC 3339.",
},
"updated_by": &schema.Schema{
"updated_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that updated the adapter.",
},
"updated_at": &schema.Schema{
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was updated. The date format follows RFC 3339.",
Expand Down
3 changes: 0 additions & 3 deletions ibm/service/kms/data_source_ibm_kms_kmip_adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func dataSourceIBMKMSKmipAdaptersList(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
if err != nil {
return err
}

// call GetKMIPAdapters api
opts := &kp.ListKmipAdaptersOptions{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func dataSourceIBMKmsKMIPClientCertificateBaseSchema() map[string]*schema.Schema
Sensitive: true,
Description: "The PEM-encoded contents of the certificate",
},
"created_by": &schema.Schema{
"created_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that created the adapter.",
},
"created_at": &schema.Schema{
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was created. The date format follows RFC 3339.",
Expand Down Expand Up @@ -101,7 +101,7 @@ func dataSourceIBMKmsKMIPClientCertRead(d *schema.ResourceData, meta interface{}
// get adapterID and certID
nameOrID, hasID := d.GetOk("adapter_id")
if !hasID {
nameOrID, hasID = d.GetOk("adapter_name")
nameOrID = d.Get("adapter_name")
}
adapterNameOrID := nameOrID.(string)

Expand Down
18 changes: 9 additions & 9 deletions ibm/service/kms/data_source_ibm_kms_kmip_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,47 @@ func dataSourceIBMKMSKMIPObjectBaseSchema(isForList bool) map[string]*schema.Sch
Computed: true,
Description: "The state of the KMIP object",
},
"created_by": &schema.Schema{
"created_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that created the adapter.",
},
"created_at": &schema.Schema{
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was created. The date format follows RFC 3339.",
},
"created_by_cert_id": &schema.Schema{
"created_by_cert_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the certificate that created the object",
},
"updated_by": &schema.Schema{
"updated_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that updated the adapter.",
},
"updated_at": &schema.Schema{
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was updated. The date format follows RFC 3339.",
},
"updated_by_cert_id": &schema.Schema{
"updated_by_cert_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the certificate that updated the object",
},
"destroyed_by": &schema.Schema{
"destroyed_by": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier that is associated with the entity that destroyed the adapter.",
},
"destroyed_at": &schema.Schema{
"destroyed_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date when a resource was destroyed. The date format follows RFC 3339.",
},
"destroyed_by_cert_id": &schema.Schema{
"destroyed_by_cert_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the certificate that destroyed the object",
Expand Down
3 changes: 3 additions & 0 deletions ibm/service/kms/data_source_ibm_kms_kmip_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func dataSourceIBMKmsKMIPObjectList(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("[ERROR] Error setting adapter_name: %s", err)
}
objs, err := kpAPI.GetKMIPObjects(ctx, adapterNameOrID, opts)
if err != nil {
return fmt.Errorf("[ERROR] Error while retriving KMIP objects associated with adapter ID '%s': %v", adapter.ID, err)
}
objsList := objs.Objects
// set computed values
mySlice := make([]map[string]interface{}, 0, len(objsList))
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/kms/resource_ibm_kms_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func resourceIBMKmsKeyDelete(d *schema.ResourceData, meta interface{}) error {
if err1 != nil {
registrations := d.Get("registrations").([]interface{})
var registrationLog error
if registrations != nil && len(registrations) > 0 {
if len(registrations) > 0 {
resourceCrns := make([]string, 0)
for _, registration := range registrations {
r := registration.(map[string]interface{})
Expand Down
45 changes: 23 additions & 22 deletions ibm/service/kms/resource_ibm_kms_key_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,30 @@ func TestAccIBMKMSResource_Key_Alias_Key_Check(t *testing.T) {
})
}

func TestAccIBMKMSResource_Key_Alias_Key_Limit(t *testing.T) {
instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
// cosInstanceName := fmt.Sprintf("cos_%d", acctest.RandIntRange(10, 100))
// bucketName := fmt.Sprintf("bucket-test77")
aliasName := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
aliasName2 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
aliasName3 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
aliasName4 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
aliasName5 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
aliasName6 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))
// Developer note: Test is disabled as a bug exists where this is not properly testable
// func TestAccIBMKMSResource_Key_Alias_Key_Limit(t *testing.T) {
// instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
// // cosInstanceName := fmt.Sprintf("cos_%d", acctest.RandIntRange(10, 100))
// // bucketName := fmt.Sprintf("bucket-test77")
// aliasName := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// aliasName2 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// aliasName3 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// aliasName4 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// aliasName5 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// aliasName6 := fmt.Sprintf("alias_%d", acctest.RandIntRange(10, 100))
// keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMKmsResourceAliasLimitConfig(instanceName, keyName, aliasName, aliasName2, aliasName3, aliasName4, aliasName5, aliasName6),
ExpectError: regexp.MustCompile("(KEY_ALIAS_QUOTA_ERR)"),
},
},
})
}
// resource.Test(t, resource.TestCase{
// PreCheck: func() { acc.TestAccPreCheck(t) },
// Providers: acc.TestAccProviders,
// Steps: []resource.TestStep{
// {
// Config: testAccCheckIBMKmsResourceAliasLimitConfig(instanceName, keyName, aliasName, aliasName2, aliasName3, aliasName4, aliasName5, aliasName6),
// ExpectError: regexp.MustCompile("(KEY_ALIAS_QUOTA_ERR)"),
// },
// },
// })
// }

func testAccCheckIBMKmsResourceAliasConfig(instanceName, KeyName, aliasName string) string {
return fmt.Sprintf(`
Expand Down
156 changes: 79 additions & 77 deletions ibm/service/kms/resource_ibm_kms_key_rings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,46 +70,47 @@ func TestAccIBMKMSResource_Key_Ring_Not_Exist(t *testing.T) {
})
}

func TestAccIBMKMSResource_Key_Ring_ForceDeleteFalse(t *testing.T) {
instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))
keyRing := fmt.Sprintf("keyRing%d", acctest.RandIntRange(10, 100))
// Developer note: Test is disabled as a bug exists where this is not properly testable
// func TestAccIBMKMSResource_Key_Ring_ForceDeleteFalse(t *testing.T) {
// instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
// keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))
// keyRing := fmt.Sprintf("keyRing%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
// Create a Key Ring and check force_delete is false
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, false), WithResourceKMSKey(keyName, "ibm_kms_key_rings.test.key_ring_id")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("ibm_kms_key.test", "key_name", keyName),
resource.TestCheckResourceAttr("ibm_kms_key.test", "key_ring_id", keyRing),
resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "false"),
),
},
// Developer note: We cannot move key rings to default key ring as we have not implemented that PATCH endpoint in terraform. Therefore we must depend on the force_delete flag to clean up test cases
// Attempt to delete the key ring and key
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithDataKMSKeys()),
ExpectError: regexp.MustCompile("KEY_RING_NOT_EMPTY_ERR:"),
},
// Update key ring to force_delete for cleanup
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "true"),
),
},
// Delete Key Ring
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithDataKMSKeys()),
ExpectError: regexp.MustCompile(`\[ERROR\] No keys in instance`),
},
// Developer note: There is no support for listing keys under a certain key state so we cannot verify deleted key is now in default key ring
},
})
}
// resource.Test(t, resource.TestCase{
// PreCheck: func() { acc.TestAccPreCheck(t) },
// Providers: acc.TestAccProviders,
// Steps: []resource.TestStep{
// // Create a Key Ring and check force_delete is false
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, false), WithResourceKMSKey(keyName, "ibm_kms_key_rings.test.key_ring_id")),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("ibm_kms_key.test", "key_name", keyName),
// resource.TestCheckResourceAttr("ibm_kms_key.test", "key_ring_id", keyRing),
// resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "false"),
// ),
// },
// // Developer note: We cannot move key rings to default key ring as we have not implemented that PATCH endpoint in terraform. Therefore we must depend on the force_delete flag to clean up test cases
// // Attempt to delete the key ring and key
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName)),
// ExpectError: regexp.MustCompile("KEY_RING_NOT_EMPTY_ERR:"),
// },
// // Update key ring to force_delete for cleanup
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true)),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "true"),
// ),
// },
// // Delete Key Ring
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithDataKMSKeys()),
// ExpectError: regexp.MustCompile(`\[ERROR\] No keys in instance`),
// },
// // Developer note: There is no support for listing keys under a certain key state so we cannot verify deleted key is now in default key ring
// },
// })
// }

func TestAccIBMKMSResource_Key_Ring_ForceDeleteTrue(t *testing.T) {
instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -148,45 +149,46 @@ func TestAccIBMKMSResource_Key_Ring_ForceDeleteTrue(t *testing.T) {
})
}

func TestAccIBMKMSResource_Key_Ring_ForceDeleteTrueContainsActiveKeys(t *testing.T) {
instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))
keyRing := fmt.Sprintf("keyRing%d", acctest.RandIntRange(10, 100))
// Developer note: Test is disabled as a bug exists where this is not properly testable
// func TestAccIBMKMSResource_Key_Ring_ForceDeleteTrueContainsActiveKeys(t *testing.T) {
// instanceName := fmt.Sprintf("tf_kms_%d", acctest.RandIntRange(10, 100))
// keyName := fmt.Sprintf("key_%d", acctest.RandIntRange(10, 100))
// keyRing := fmt.Sprintf("keyRing%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
// Create a Key Ring and check force_delete is true
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true), WithResourceKMSKey(keyName, "ibm_kms_key_rings.test.key_ring_id")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("ibm_kms_key.test", "key_name", keyName),
resource.TestCheckResourceAttr("ibm_kms_key.test", "key_ring_id", keyRing),
resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "true"),
),
},
// Attempt to delete the key ring while active key exists
// We must specify key ring ID and not reference here as the resource is removed
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKey(keyName, keyRing)),
ExpectError: regexp.MustCompile("KEY_RING_KEYS_NOT_DELETED_ERR:"),
},
// Attempt to delete keys
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true)),
},
// Attempt to delete key ring and check no more keys
{
Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithDataKMSKeys()),
ExpectError: regexp.MustCompile(`\[ERROR\] No keys in instance`),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ibm_kms_key_rings.test_key_rings", "key_rings.0.id", "default"),
),
},
},
})
}
// resource.Test(t, resource.TestCase{
// PreCheck: func() { acc.TestAccPreCheck(t) },
// Providers: acc.TestAccProviders,
// Steps: []resource.TestStep{
// // Create a Key Ring and check force_delete is true
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true), WithResourceKMSKey(keyName, "ibm_kms_key_rings.test.key_ring_id")),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("ibm_kms_key.test", "key_name", keyName),
// resource.TestCheckResourceAttr("ibm_kms_key.test", "key_ring_id", keyRing),
// resource.TestCheckResourceAttr("ibm_kms_key_rings.test", "force_delete", "true"),
// ),
// },
// // Attempt to delete the key ring while active key exists
// // We must specify key ring ID and not reference here as the resource is removed
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKey(keyName, keyRing)),
// ExpectError: regexp.MustCompile("KEY_RING_KEYS_NOT_DELETED_ERR:"),
// },
// // Attempt to delete keys
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithResourceKMSKeyRing(keyRing, true)),
// },
// // Attempt to delete key ring and check no more keys
// {
// Config: buildResourceSet(WithResourceKMSInstance(instanceName), WithDataKMSKeys()),
// ExpectError: regexp.MustCompile(`\[ERROR\] No keys in instance`),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("data.ibm_kms_key_rings.test_key_rings", "key_rings.0.id", "default"),
// ),
// },
// },
// })
// }

type CreateResourceOption func(resourceText *string)

Expand Down
Loading