Skip to content

Commit

Permalink
Merge pull request #356 from terraform-providers/keyvault-key
Browse files Browse the repository at this point in the history
New Resource: `azurerm_key_vault_key`
  • Loading branch information
tombuildsstuff authored Sep 27, 2017
2 parents fd47456 + 87344c9 commit 3bc8e3f
Show file tree
Hide file tree
Showing 10 changed files with 954 additions and 19 deletions.
26 changes: 15 additions & 11 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,17 +654,7 @@ func (c *Config) getArmClient() (*ArmClient, error) {
aschc.Sender = sender
client.automationScheduleClient = aschc

kvc := keyvault.NewVaultsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&kvc.Client)
kvc.Authorizer = auth
kvc.Sender = sender
client.keyVaultClient = kvc

kvmc := keyVault.New()
setUserAgent(&kvmc.Client)
kvmc.Authorizer = keyVaultAuth
kvmc.Sender = sender
client.keyVaultManagementClient = kvmc
client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth, sender)

client.registerDatabases(endpoint, c.SubscriptionID, auth, sender)

Expand Down Expand Up @@ -748,6 +738,20 @@ func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth auto
c.sqlServersClient = sqlSrvClient
}

func (c *ArmClient) registerKeyVaultClients(endpoint, subscriptionId string, auth autorest.Authorizer, keyVaultAuth autorest.Authorizer, sender autorest.Sender) {
keyVaultClient := keyvault.NewVaultsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&keyVaultClient.Client)
keyVaultClient.Authorizer = auth
keyVaultClient.Sender = sender
c.keyVaultClient = keyVaultClient

keyVaultManagementClient := keyVault.New()
setUserAgent(&keyVaultManagementClient.Client)
keyVaultManagementClient.Authorizer = keyVaultAuth
keyVaultManagementClient.Sender = sender
c.keyVaultManagementClient = keyVaultManagementClient
}

func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAccountName string) (string, bool, error) {
accountKeys, err := armClient.storageServiceClient.ListKeys(resourceGroupName, storageAccountName)
if accountKeys.StatusCode == http.StatusNotFound {
Expand Down
104 changes: 104 additions & 0 deletions azurerm/import_arm_key_vault_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMKeyVaultKey_importBasicEC(t *testing.T) {
resourceName := "azurerm_key_vault_key.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultKey_basicEC(rs, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"key_size"},
},
},
})
}

func TestAccAzureRMKeyVaultKey_importBasicRSA(t *testing.T) {
resourceName := "azurerm_key_vault_key.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultKey_basicRSA(rs, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"key_size"},
},
},
})
}

func TestAccAzureRMKeyVaultKey_importBasicRSAHSM(t *testing.T) {
resourceName := "azurerm_key_vault_key.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultKey_basicRSAHSM(rs, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"key_size"},
},
},
})
}

func TestAccAzureRMKeyVaultKey_importComplete(t *testing.T) {
resourceName := "azurerm_key_vault_key.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultKey_complete(rs, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"key_size"},
},
},
})
}
4 changes: 2 additions & 2 deletions azurerm/import_arm_key_vault_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestAccAzureRMKeyVaultSecret_importBasic(t *testing.T) {
resourceName := "azurerm_key_vault.test"
resourceName := "azurerm_key_vault_secret.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultSecret_basic(rs, testLocation())
Expand All @@ -31,7 +31,7 @@ func TestAccAzureRMKeyVaultSecret_importBasic(t *testing.T) {
}

func TestAccAzureRMKeyVaultSecret_importComplete(t *testing.T) {
resourceName := "azurerm_key_vault.test"
resourceName := "azurerm_key_vault_secret.test"

rs := acctest.RandString(6)
config := testAccAzureRMKeyVaultSecret_complete(rs, testLocation())
Expand Down
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_express_route_circuit": resourceArmExpressRouteCircuit(),
"azurerm_image": resourceArmImage(),
"azurerm_key_vault": resourceArmKeyVault(),
"azurerm_key_vault_key": resourceArmKeyVaultKey(),
"azurerm_key_vault_secret": resourceArmKeyVaultSecret(),
"azurerm_lb": resourceArmLoadBalancer(),
"azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(),
Expand Down
Loading

0 comments on commit 3bc8e3f

Please sign in to comment.