Skip to content

Commit

Permalink
Update eventhub_namespace_customer_managed_key_resource.go
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte authored Oct 27, 2023
1 parent 5a89a56 commit 87e9ae7
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func resourceEventHubNamespaceCustomerManagedKeyCreateUpdate(d *pluginsdk.Resour
}

userAssignedIdentity := d.Get("user_assigned_identity_id").(string)
if userAssignedIdentity != "" {
if userAssignedIdentity != "" && keyVaultProps != nil {

// this provides a more helpful error message than the API response
if namespace.Identity == nil {
return fmt.Errorf("user assigned identity '%s' must also be assigned to the parent event hub - currently no user assigned identities are assigned to the parent event hub", userAssignedIdentity)
Expand Down Expand Up @@ -208,17 +209,18 @@ func resourceEventHubNamespaceCustomerManagedKeyRead(d *pluginsdk.ResourceData,
d.Set("key_vault_key_ids", keyVaultKeyIds)
d.Set("infrastructure_encryption_enabled", props.Encryption.RequireInfrastructureEncryption)

if props.Encryption.KeyVaultProperties != nil {
if kvprops := props.Encryption.KeyVaultProperties; kvprops != nil {
// we can only have a single user managed id for N number of keys, azure portal only allows setting a single one and then applies it to each key
for _, item := range *props.Encryption.KeyVaultProperties {
if item.Identity != nil {
for _, item := range *kvprops {
if item.Identity != nil && item.Identity.UserAssignedIdentity != nil {
userAssignedId, err := commonids.ParseUserAssignedIdentityIDInsensitively(*item.Identity.UserAssignedIdentity)
if err != nil {
return fmt.Errorf("parsing `user_assigned_identity_id`: %+v", err)
}
if err := d.Set("user_assigned_identity_id", userAssignedId.ID()); err != nil {
return fmt.Errorf("setting `user_assigned_identity_id`: %+v", err)
}

break
}
}
Expand Down

0 comments on commit 87e9ae7

Please sign in to comment.