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

Requiring Import (PR 6 of ...) #2728

Merged
merged 32 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
54b33db
r/key_vault_certificate: requiring imports
tombuildsstuff Jan 21, 2019
51ff045
r/key_vault_key: requires import
tombuildsstuff Jan 21, 2019
df10cb4
r/key_vault_secret: requires import
tombuildsstuff Jan 21, 2019
1998423
r/kubernetes_cluster: requiring imports
tombuildsstuff Jan 21, 2019
fd851cf
r/load_balancer: requiring import
tombuildsstuff Jan 21, 2019
a0d42a2
r/lb_backend_address_pool: requiring imports
tombuildsstuff Jan 21, 2019
7a45c5f
r/lb_nat_pool: requires import
tombuildsstuff Jan 21, 2019
b2f3122
r/lb_nat_rule: requires import
tombuildsstuff Jan 21, 2019
2d61b72
r/lb_probe: requires import
tombuildsstuff Jan 21, 2019
bcb5633
r/loadbalancer_rule: requires import
tombuildsstuff Jan 21, 2019
9fbead0
r/local_network_gateway: requiring imports
tombuildsstuff Jan 21, 2019
226a150
r/log_analytics_solution: requiring imports
tombuildsstuff Jan 21, 2019
b40475f
r/log_analytics_workspace: requiring import
tombuildsstuff Jan 21, 2019
1593520
refactor notes: log_analytics_workspace_linked_service
tombuildsstuff Jan 21, 2019
db3fd33
refactoring the log_analytics_workspace_linked_service resource
tombuildsstuff Jan 21, 2019
02f8f0f
r/log_analytics_workspace_linked_service: requiring import
tombuildsstuff Jan 21, 2019
75ebd6f
r/logic_app_action|trigger: requiring import
tombuildsstuff Jan 21, 2019
fe9b6d9
r/logic_app_workflow: requiring import
tombuildsstuff Jan 21, 2019
609812a
r/managed_disk: requiring import
tombuildsstuff Jan 21, 2019
0e72636
r/management_group: requiring imports
tombuildsstuff Jan 21, 2019
9eb3645
r/management_lock: requiring import
tombuildsstuff Jan 21, 2019
78f360d
r/mariadb_database: testing import
tombuildsstuff Jan 21, 2019
3c0bec8
r/mariadb_database: requiring imports
tombuildsstuff Jan 21, 2019
70d7c99
r/mariadb_server: requiring import
tombuildsstuff Jan 21, 2019
e12b611
r/metric_alertrule: requiring import
tombuildsstuff Jan 21, 2019
ddfa16c
r/monitor_action_group: requiring imports
tombuildsstuff Jan 21, 2019
786e4ab
r/monitor_activity_log_alert: requiring import
tombuildsstuff Jan 21, 2019
86d4190
r/monitor_diagnostic_setting: requiring import
tombuildsstuff Jan 21, 2019
e33e5b9
r/monitor_log_profile: requiring import
tombuildsstuff Jan 21, 2019
d7cae57
r/monitor_metric_alert: requiring import
tombuildsstuff Jan 21, 2019
c052829
r/mssql_elasticpool: requiring imports
tombuildsstuff Jan 21, 2019
eb29cbf
Fixing issues from code review
tombuildsstuff Jan 22, 2019
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
22 changes: 16 additions & 6 deletions azurerm/logic_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (

"github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

// NOTE: this file is not a recommended way of developing Terraform resources; this exists to work around the fact that this API is dynamic (by it's nature)

func resourceLogicAppActionUpdate(d *schema.ResourceData, meta interface{}, logicAppId string, name string, vals map[string]interface{}) error {
return resourceLogicAppComponentUpdate(d, meta, "Action", "actions", logicAppId, name, vals)
func resourceLogicAppActionUpdate(d *schema.ResourceData, meta interface{}, logicAppId string, name string, vals map[string]interface{}, resourceName string) error {
return resourceLogicAppComponentUpdate(d, meta, "Action", "actions", logicAppId, name, vals, resourceName)
}

func resourceLogicAppTriggerUpdate(d *schema.ResourceData, meta interface{}, logicAppId string, name string, vals map[string]interface{}) error {
return resourceLogicAppComponentUpdate(d, meta, "Trigger", "triggers", logicAppId, name, vals)
func resourceLogicAppTriggerUpdate(d *schema.ResourceData, meta interface{}, logicAppId string, name string, vals map[string]interface{}, resourceName string) error {
return resourceLogicAppComponentUpdate(d, meta, "Trigger", "triggers", logicAppId, name, vals, resourceName)
}

func resourceLogicAppComponentUpdate(d *schema.ResourceData, meta interface{}, kind string, propertyName string, logicAppId string, name string, vals map[string]interface{}) error {
func resourceLogicAppComponentUpdate(d *schema.ResourceData, meta interface{}, kind string, propertyName string, logicAppId string, name string, vals map[string]interface{}, resourceName string) error {
client := meta.(*ArmClient).logicWorkflowsClient
ctx := meta.(*ArmClient).StopContext

Expand Down Expand Up @@ -54,8 +55,17 @@ func resourceLogicAppComponentUpdate(d *schema.ResourceData, meta interface{}, k
return fmt.Errorf("[ERROR] Error parsing Logic App Workflow - `WorkflowProperties.Definition` is nil")
}

resourceId := fmt.Sprintf("%s/%s/%s", *read.ID, propertyName, name)

definition := read.WorkflowProperties.Definition.(map[string]interface{})
vs := definition[propertyName].(map[string]interface{})

if requireResourcesToBeImported {
if _, hasExisting := vs[name]; hasExisting {
return tf.ImportAsExistsError(resourceName, resourceId)
}
}

vs[name] = vals
definition[propertyName] = vs

Expand All @@ -73,7 +83,7 @@ func resourceLogicAppComponentUpdate(d *schema.ResourceData, meta interface{}, k
}

if d.IsNewResource() {
d.SetId(fmt.Sprintf("%s/%s/%s", *read.ID, propertyName, name))
d.SetId(resourceId)
}

return nil
Expand Down
16 changes: 15 additions & 1 deletion azurerm/resource_arm_key_vault_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -302,8 +303,21 @@ func resourceArmKeyVaultCertificateCreate(d *schema.ResourceData, meta interface

name := d.Get("name").(string)
keyVaultBaseUrl := d.Get("vault_uri").(string)
tags := d.Get("tags").(map[string]interface{})

if requireResourcesToBeImported {
existing, err := client.GetCertificate(ctx, keyVaultBaseUrl, name, "")
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Certificate %q (Key Vault %q): %s", name, keyVaultBaseUrl, err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_key_vault_certificate", *existing.ID)
}
}

tags := d.Get("tags").(map[string]interface{})
policy := expandKeyVaultCertificatePolicy(d)

if v, ok := d.GetOk("certificate"); ok {
Expand Down
63 changes: 63 additions & 0 deletions azurerm/resource_arm_key_vault_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ func TestAccAzureRMKeyVaultCertificate_basicImportPFX(t *testing.T) {
})
}

func TestAccAzureRMKeyVaultCertificate_requiresImport(t *testing.T) {
if !requireResourcesToBeImported {
t.Skip("Skipping since resources aren't required to be imported")
return
}

resourceName := "azurerm_key_vault_certificate.test"
rs := acctest.RandString(6)
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultCertificateDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKeyVaultCertificate_basicImportPFX(rs, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKeyVaultCertificateExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "certificate_data"),
),
},
{
Config: testAccAzureRMKeyVaultCertificate_requiresImport(rs, location),
ExpectError: testRequiresImportError("azurerm_key_vault_certificate"),
},
},
})
}

func TestAccAzureRMKeyVaultCertificate_disappears(t *testing.T) {
resourceName := "azurerm_key_vault_certificate.test"
rs := acctest.RandString(6)
Expand Down Expand Up @@ -331,6 +361,39 @@ resource "azurerm_key_vault_certificate" "test" {
`, rString, location, rString, rString)
}

func testAccAzureRMKeyVaultCertificate_requiresImport(rString string, location string) string {
template := testAccAzureRMKeyVaultCertificate_basicImportPFX(rString, location)
return fmt.Sprintf(`
%s

resource "azurerm_key_vault_certificate" "import" {
name = "${azurerm_key_vault_certificate.test.name}"
vault_uri = "${azurerm_key_vault_certificate.test.vault_uri}"

certificate {
contents = "${base64encode(file("testdata/keyvaultcert.pfx"))}"
password = ""
}

certificate_policy {
issuer_parameters {
name = "Self"
}

key_properties {
exportable = true
key_size = 2048
key_type = "RSA"
reuse_key = false
}

secret_properties {
content_type = "application/x-pkcs12"
}
}
}`, template)
}

func testAccAzureRMKeyVaultCertificate_basicGenerate(rString string, location string) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
Expand Down
14 changes: 14 additions & 0 deletions azurerm/resource_arm_key_vault_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -105,6 +106,19 @@ func resourceArmKeyVaultKeyCreate(d *schema.ResourceData, meta interface{}) erro
name := d.Get("name").(string)
keyVaultBaseUrl := d.Get("vault_uri").(string)

if requireResourcesToBeImported {
existing, err := client.GetKey(ctx, keyVaultBaseUrl, name, "")
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Key %q (Key Vault %q): %s", name, keyVaultBaseUrl, err)
}
}

if existing.Key != nil && existing.Key.Kid != nil && *existing.Key.Kid != "" {
return tf.ImportAsExistsError("azurerm_key_vault_key", *existing.Key.Kid)
}
}

keyType := d.Get("key_type").(string)
keyOptions := expandKeyVaultKeyOptions(d)
tags := d.Get("tags").(map[string]interface{})
Expand Down
48 changes: 48 additions & 0 deletions azurerm/resource_arm_key_vault_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ func TestAccAzureRMKeyVaultKey_basicEC(t *testing.T) {
})
}

func TestAccAzureRMKeyVaultKey_requiresImport(t *testing.T) {
if !requireResourcesToBeImported {
t.Skip("Skipping since resources aren't required to be imported")
return
}

resourceName := "azurerm_key_vault_key.test"
rs := acctest.RandString(6)
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKeyVaultKey_basicEC(rs, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKeyVaultKeyExists(resourceName),
),
},
{
Config: testAccAzureRMKeyVaultKey_requiresImport(rs, location),
ExpectError: testRequiresImportError("azurerm_key_vault_key"),
},
},
})
}

func TestAccAzureRMKeyVaultKey_basicRSA(t *testing.T) {
resourceName := "azurerm_key_vault_key.test"
rs := acctest.RandString(6)
Expand Down Expand Up @@ -325,6 +354,25 @@ resource "azurerm_key_vault_key" "test" {
`, rString, location, rString, rString)
}

func testAccAzureRMKeyVaultKey_requiresImport(rString string, location string) string {
template := testAccAzureRMKeyVaultKey_basicEC(rString, location)
return fmt.Sprintf(`
%s

resource "azurerm_key_vault_key" "import" {
name = "${azurerm_key_vault_key.test.name}"
vault_uri = "${azurerm_key_vault_key.test.vault_uri}"
key_type = "EC"
key_size = 2048

key_opts = [
"sign",
"verify",
]
}
`, template)
}

func testAccAzureRMKeyVaultKey_basicRSA(rString string, location string) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
Expand Down
15 changes: 15 additions & 0 deletions azurerm/resource_arm_key_vault_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -65,6 +66,20 @@ func resourceArmKeyVaultSecretCreate(d *schema.ResourceData, meta interface{}) e

name := d.Get("name").(string)
keyVaultBaseUrl := d.Get("vault_uri").(string)

if requireResourcesToBeImported {
existing, err := client.GetSecret(ctx, keyVaultBaseUrl, name, "")
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Secret %q (Key Vault %q): %s", name, keyVaultBaseUrl, err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_key_vault_secret", *existing.ID)
}
}

value := d.Get("value").(string)
contentType := d.Get("content_type").(string)
tags := d.Get("tags").(map[string]interface{})
Expand Down
43 changes: 43 additions & 0 deletions azurerm/resource_arm_key_vault_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ func TestAccAzureRMKeyVaultSecret_basic(t *testing.T) {
})
}

func TestAccAzureRMKeyVaultSecret_requiresImport(t *testing.T) {
if !requireResourcesToBeImported {
t.Skip("Skipping since resources aren't required to be imported")
return
}

resourceName := "azurerm_key_vault_secret.test"
rs := acctest.RandString(6)
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKeyVaultSecretDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKeyVaultSecret_basic(rs, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKeyVaultSecretExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "value", "rick-and-morty"),
),
},
{
Config: testAccAzureRMKeyVaultSecret_requiresImport(rs, location),
ExpectError: testRequiresImportError("azurerm_key_vault_secret"),
},
},
})
}

func TestAccAzureRMKeyVaultSecret_disappears(t *testing.T) {
resourceName := "azurerm_key_vault_secret.test"
rs := acctest.RandString(6)
Expand Down Expand Up @@ -261,6 +291,19 @@ resource "azurerm_key_vault_secret" "test" {
`, rString, location, rString, rString)
}

func testAccAzureRMKeyVaultSecret_requiresImport(rString string, location string) string {
template := testAccAzureRMKeyVaultSecret_basic(rString, location)
return fmt.Sprintf(`
%s

resource "azurerm_key_vault_secret" "import" {
name = "${azurerm_key_vault_secret.test.name}"
value = "${azurerm_key_vault_secret.test.value}"
vault_uri = "${azurerm_key_vault_secret.test.vault_uri}"
}
`, template)
}

func testAccAzureRMKeyVaultSecret_complete(rString string, location string) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
Expand Down
15 changes: 15 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/kubernetes"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -493,6 +494,20 @@ func resourceArmKubernetesClusterCreateUpdate(d *schema.ResourceData, meta inter

resGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

if requireResourcesToBeImported && d.IsNewResource() {
existing, err := client.Get(ctx, resGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Kubernetes Cluster %q (Resource Group %q): %s", name, resGroup, err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_kubernetes_cluster", *existing.ID)
}
}

location := azureRMNormalizeLocation(d.Get("location").(string))
dnsPrefix := d.Get("dns_prefix").(string)
kubernetesVersion := d.Get("kubernetes_version").(string)
Expand Down
Loading