From 653c6d09c66af349f56761a45dc41b1ac4391aa0 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 12 Jul 2018 12:21:03 -0700 Subject: [PATCH 1/5] VMSS: changed sku property from a set to list --- .../resource_arm_virtual_machine_scale_set.go | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_scale_set.go b/azurerm/resource_arm_virtual_machine_scale_set.go index ff5f9c94b546f..691df7c925df4 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/azurerm/resource_arm_virtual_machine_scale_set.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" "log" - "strings" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute" + "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/structure" @@ -69,14 +69,15 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { }, "sku": { - Type: schema.TypeSet, + Type: schema.TypeList, Required: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, }, "tier": { @@ -92,7 +93,6 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineScaleSetSkuHash, }, "license_type": { @@ -1323,21 +1323,6 @@ func resourceArmVirtualMachineScaleSetStorageProfileImageReferenceHash(v interfa return hashcode.String(buf.String()) } -func resourceArmVirtualMachineScaleSetSkuHash(v interface{}) int { - var buf bytes.Buffer - - if m, ok := v.(map[string]interface{}); ok { - buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - buf.WriteString(fmt.Sprintf("%d-", m["capacity"].(int))) - - if v, ok := m["tier"]; ok { - buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(v.(string)))) - } - } - - return hashcode.String(buf.String()) -} - func resourceArmVirtualMachineScaleSetStorageProfileOsDiskHash(v interface{}) int { var buf bytes.Buffer @@ -1418,20 +1403,15 @@ func resourceArmVirtualMachineScaleSetExtensionHash(v interface{}) int { } func expandVirtualMachineScaleSetSku(d *schema.ResourceData) (*compute.Sku, error) { - skuConfig := d.Get("sku").(*schema.Set).List() - + skuConfig := d.Get("sku").([]interface{}) config := skuConfig[0].(map[string]interface{}) - name := config["name"].(string) - tier := config["tier"].(string) - capacity := int64(config["capacity"].(int)) - sku := &compute.Sku{ - Name: &name, - Capacity: &capacity, + Name: utils.String(config["name"].(string)), + Capacity: utils.Int64(int64(config["capacity"].(int))), } - if tier != "" { + if tier, ok := config["tier"].(string); ok && tier != "" { sku.Tier = &tier } From d5deb91b35e0ff38a807cc0e683d664710233628 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Fri, 13 Jul 2018 19:35:34 +0300 Subject: [PATCH 2/5] resouce/app_insights: Allow different application_type deployments (#1563) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #822 This follows the work in the API to allow types like web, other, java, store, phone and ios ``` ▶ acctests azurerm TestAccAzureRMApplicationInsights_ === RUN TestAccAzureRMApplicationInsights_importBasicWeb --- PASS: TestAccAzureRMApplicationInsights_importBasicWeb (99.07s) === RUN TestAccAzureRMApplicationInsights_importBasicOther --- PASS: TestAccAzureRMApplicationInsights_importBasicOther (96.48s) === RUN TestAccAzureRMApplicationInsights_basicWeb --- PASS: TestAccAzureRMApplicationInsights_basicWeb (84.27s) === RUN TestAccAzureRMApplicationInsights_basicJava --- PASS: TestAccAzureRMApplicationInsights_basicJava (79.28s) === RUN TestAccAzureRMApplicationInsights_basicOther --- PASS: TestAccAzureRMApplicationInsights_basicOther (73.29s) === RUN TestAccAzureRMApplicationInsights_basicPhone --- PASS: TestAccAzureRMApplicationInsights_basicPhone (73.88s) === RUN TestAccAzureRMApplicationInsights_basicStore --- PASS: TestAccAzureRMApplicationInsights_basicStore (68.69s) === RUN TestAccAzureRMApplicationInsights_basiciOS --- PASS: TestAccAzureRMApplicationInsights_basiciOS (76.30s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 651.307s ``` --- .../import_arm_application_insights_test.go | 4 +- azurerm/resource_arm_application_insights.go | 8 +- .../resource_arm_application_insights_test.go | 112 ++++++++++++++---- .../docs/r/application_insights.html.markdown | 2 +- 4 files changed, 100 insertions(+), 26 deletions(-) diff --git a/azurerm/import_arm_application_insights_test.go b/azurerm/import_arm_application_insights_test.go index 657dc8ee420c6..5f5ab02965da9 100644 --- a/azurerm/import_arm_application_insights_test.go +++ b/azurerm/import_arm_application_insights_test.go @@ -11,7 +11,7 @@ func TestAccAzureRMApplicationInsights_importBasicWeb(t *testing.T) { resourceName := "azurerm_application_insights.test" ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basicWeb(ri, testLocation()) + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "web") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -35,7 +35,7 @@ func TestAccAzureRMApplicationInsights_importBasicOther(t *testing.T) { resourceName := "azurerm_application_insights.test" ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basicWeb(ri, testLocation()) + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "web") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/azurerm/resource_arm_application_insights.go b/azurerm/resource_arm_application_insights.go index 54abebb20e5e7..7bc184f4ef705 100644 --- a/azurerm/resource_arm_application_insights.go +++ b/azurerm/resource_arm_application_insights.go @@ -38,8 +38,12 @@ func resourceArmApplicationInsights() *schema.Resource { ForceNew: true, DiffSuppressFunc: ignoreCaseDiffSuppressFunc, ValidateFunc: validation.StringInSlice([]string{ - string(insights.Web), - string(insights.Other), + "web", + "other", + "java", + "phone", + "store", + "ios", }, true), }, diff --git a/azurerm/resource_arm_application_insights_test.go b/azurerm/resource_arm_application_insights_test.go index f627d025c5ae9..c5e5a2523d495 100644 --- a/azurerm/resource_arm_application_insights_test.go +++ b/azurerm/resource_arm_application_insights_test.go @@ -13,7 +13,7 @@ import ( func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basicWeb(ri, testLocation()) + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "web") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -24,6 +24,28 @@ func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "web"), + ), + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_basicJava(t *testing.T) { + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "java") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "java"), ), }, }, @@ -33,7 +55,7 @@ func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basicOther(ri, testLocation()) + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "other") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -44,6 +66,70 @@ func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "other"), + ), + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_basicPhone(t *testing.T) { + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "phone") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "phone"), + ), + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_basicStore(t *testing.T) { + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "store") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "store"), + ), + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_basiciOS(t *testing.T) { + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basic(ri, testLocation(), "ios") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + resource.TestCheckResourceAttr("azurerm_application_insights.test", "application_type", "ios"), ), }, }, @@ -106,23 +192,7 @@ func testCheckAzureRMApplicationInsightsExists(name string) resource.TestCheckFu } } -func testAccAzureRMApplicationInsights_basicWeb(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_application_insights" "test" { - name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - application_type = "web" -} -`, rInt, location, rInt) -} - -func testAccAzureRMApplicationInsights_basicOther(rInt int, location string) string { +func testAccAzureRMApplicationInsights_basic(rInt int, location string, applicationType string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -133,7 +203,7 @@ resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - application_type = "other" + application_type = "%s" } -`, rInt, location, rInt) +`, rInt, location, rInt, applicationType) } diff --git a/website/docs/r/application_insights.html.markdown b/website/docs/r/application_insights.html.markdown index 69041b5c420a0..dfe42114075b9 100644 --- a/website/docs/r/application_insights.html.markdown +++ b/website/docs/r/application_insights.html.markdown @@ -46,7 +46,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `application_type` - (Required) Specifies the type of Application Insights to create. Valid values are `Web` and `Other`. +* `application_type` - (Required) Specifies the type of Application Insights to create. Valid values are `Web`, `Java`, `Phone`, `Store`, `iOS` and `Other`. * `tags` - (Optional) A mapping of tags to assign to the resource. From ee414c381c5a001d5620d43d6fc692e7eb503711 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Fri, 13 Jul 2018 18:36:28 +0200 Subject: [PATCH 3/5] Updating to include #1563 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d77832716e5..3acfe3de35421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ FEATURES: BUG FIXES: +* `azurerm_application_insights` - fixing a bug where `application_type` was set to `other` [GH-1563] * `azurerm_traffic_manager_endpoint` - working around a bug in the API by setting `target` to nil when a `target_resource_id` is specified [GH-1546] ## 1.9.0 (July 11, 2018) From 629f6fea0893f5a6abb1c02500d794a802af2188 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Fri, 13 Jul 2018 19:55:07 +0300 Subject: [PATCH 4/5] resource/servicebus_subscription_rule: Fix the correlation_filter optional values (#1565) Fixes: #1537 This was a simple fix to make sure that we were not passing empty strings to the API. When passing empty strings, it was including those strings in the subscription rule We should only set the part of the rule if it is required as, technically, a rule of sys.To = `` is actually value --- ...source_arm_servicebus_subscription_rule.go | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_servicebus_subscription_rule.go b/azurerm/resource_arm_servicebus_subscription_rule.go index 0a37667b2b59c..f8f3f1e3c63b2 100644 --- a/azurerm/resource_arm_servicebus_subscription_rule.go +++ b/azurerm/resource_arm_servicebus_subscription_rule.go @@ -268,15 +268,38 @@ func expandAzureRmServiceBusCorrelationFilter(d *schema.ResourceData) (*serviceb return nil, fmt.Errorf("At least one property must be set in the `correlation_filter` block") } - correlationFilter := servicebus.CorrelationFilter{ - CorrelationID: utils.String(correlationID), - MessageID: utils.String(messageID), - To: utils.String(to), - ReplyTo: utils.String(replyTo), - Label: utils.String(label), - SessionID: utils.String(sessionID), - ReplyToSessionID: utils.String(replyToSessionID), - ContentType: utils.String(contentType), + correlationFilter := servicebus.CorrelationFilter{} + + if correlationID != "" { + correlationFilter.CorrelationID = utils.String(correlationID) + } + + if messageID != "" { + correlationFilter.MessageID = utils.String(messageID) + } + + if to != "" { + correlationFilter.To = utils.String(to) + } + + if replyTo != "" { + correlationFilter.ReplyTo = utils.String(replyTo) + } + + if label != "" { + correlationFilter.Label = utils.String(label) + } + + if sessionID != "" { + correlationFilter.SessionID = utils.String(sessionID) + } + + if replyToSessionID != "" { + correlationFilter.ReplyToSessionID = utils.String(replyToSessionID) + } + + if contentType != "" { + correlationFilter.ContentType = utils.String(contentType) } return &correlationFilter, nil From 854521da21709301b38a1457e68156dcc5db3cfe Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Fri, 13 Jul 2018 18:55:28 +0200 Subject: [PATCH 5/5] Updating to include #1565 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3acfe3de35421..fcd3c6564f4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ FEATURES: BUG FIXES: * `azurerm_application_insights` - fixing a bug where `application_type` was set to `other` [GH-1563] +* `azurerm_servicebus_subscription` - only sending `correlation_filter` values if they're set [GH-1565] * `azurerm_traffic_manager_endpoint` - working around a bug in the API by setting `target` to nil when a `target_resource_id` is specified [GH-1546] ## 1.9.0 (July 11, 2018)