From c4863897a01241f0617b08110a7681ffe6ef8908 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 19 Sep 2019 14:49:29 +0200 Subject: [PATCH 1/6] add server_full_name computed property --- .../resource_arm_analysis_services_server.go | 9 ++++ ...ource_arm_analysis_services_server_test.go | 41 +++++++++++++++++++ .../r/analysis_services_server.html.markdown | 2 + 3 files changed, 52 insertions(+) diff --git a/azurerm/resource_arm_analysis_services_server.go b/azurerm/resource_arm_analysis_services_server.go index 1c8a6ce9bc8a..f1e11baa7634 100644 --- a/azurerm/resource_arm_analysis_services_server.go +++ b/azurerm/resource_arm_analysis_services_server.go @@ -96,6 +96,11 @@ func resourceArmAnalysisServicesServer() *schema.Resource { ValidateFunc: validateQuerypoolConnectionMode(), }, + "server_full_name": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -208,6 +213,10 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac } d.Set("querypool_connection_mode", string(serverProps.QuerypoolConnectionMode)) + + if serverFullName := serverProps.ServerFullName; serverFullName != nil { + d.Set("server_full_name", serverProps.ServerFullName) + } } return tags.FlattenAndSet(d, server.Tags) diff --git a/azurerm/resource_arm_analysis_services_server_test.go b/azurerm/resource_arm_analysis_services_server_test.go index 8d1a9c902aa0..c488e70a570e 100644 --- a/azurerm/resource_arm_analysis_services_server_test.go +++ b/azurerm/resource_arm_analysis_services_server_test.go @@ -192,6 +192,31 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { }) } +func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { + resourceName := "azurerm_analysis_services_server.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAnalysisServicesServerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAnalysisServicesServer_serverFullName(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAnalysisServicesServerExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "server_full_name"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccAzureRMAnalysisServicesServer_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -352,6 +377,22 @@ resource "azurerm_analysis_services_server" "test" { `, rInt, location, rInt, strings.Join(adminUsers, "\", \"")) } +func testAccAzureRMAnalysisServicesServer_serverFullName(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_analysis_services_server" "test" { + name = "acctestass%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "B1" +} +`, rInt, location, rInt) +} + func testCheckAzureRMAnalysisServicesServerDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).analysisservices.ServerClient diff --git a/website/docs/r/analysis_services_server.html.markdown b/website/docs/r/analysis_services_server.html.markdown index a705212c917d..b457d2ddfc26 100644 --- a/website/docs/r/analysis_services_server.html.markdown +++ b/website/docs/r/analysis_services_server.html.markdown @@ -75,6 +75,8 @@ In addition to all arguments above, the following attributes are exported: * `id` - The ID of the Analysis Services Server. +* `server_full_name` - The full name of the Analysis Services Server. + ## Import Analysis Services Server can be imported using the `resource id`, e.g. From 0eeb175de3c0e29c839e4563667f1f2300b31d6a Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 19 Sep 2019 19:51:10 +0200 Subject: [PATCH 2/6] add backup_blob_container_uri; no tests yet --- .../resource_arm_analysis_services_server.go | 19 +++++++++++++++++++ .../r/analysis_services_server.html.markdown | 2 ++ 2 files changed, 21 insertions(+) diff --git a/azurerm/resource_arm_analysis_services_server.go b/azurerm/resource_arm_analysis_services_server.go index f1e11baa7634..5f2da5a37336 100644 --- a/azurerm/resource_arm_analysis_services_server.go +++ b/azurerm/resource_arm_analysis_services_server.go @@ -96,6 +96,13 @@ func resourceArmAnalysisServicesServer() *schema.Resource { ValidateFunc: validateQuerypoolConnectionMode(), }, + "backup_blob_container_uri": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "server_full_name": { Type: schema.TypeString, Computed: true, @@ -217,6 +224,10 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac if serverFullName := serverProps.ServerFullName; serverFullName != nil { d.Set("server_full_name", serverProps.ServerFullName) } + + if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { + d.Set("backup_blob_container_uri", containerUri) + } } return tags.FlattenAndSet(d, server.Tags) @@ -312,6 +323,10 @@ func expandAnalysisServicesServerProperties(d *schema.ResourceData) *analysisser serverProperties.QuerypoolConnectionMode = analysisservices.ConnectionMode(querypoolConnectionMode.(string)) } + if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { + serverProperties.BackupBlobContainerURI = utils.String(containerUri.(string)) + } + return &serverProperties } @@ -324,6 +339,10 @@ func expandAnalysisServicesServerMutableProperties(d *schema.ResourceData) *anal serverProperties.QuerypoolConnectionMode = analysisservices.ConnectionMode(d.Get("querypool_connection_mode").(string)) + if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { + serverProperties.BackupBlobContainerURI = utils.String(containerUri.(string)) + } + return &serverProperties } diff --git a/website/docs/r/analysis_services_server.html.markdown b/website/docs/r/analysis_services_server.html.markdown index b457d2ddfc26..0c9b1848f206 100644 --- a/website/docs/r/analysis_services_server.html.markdown +++ b/website/docs/r/analysis_services_server.html.markdown @@ -54,6 +54,8 @@ The following arguments are supported: * `querypool_connection_mode` - (Optional) Controls how the read-write server is used in the query pool. If this values is set to `All` then read-write servers are also used for queries. Otherwise with `ReadOnly` these servers do not participate in query operations. +* `backup_blob_container_uri` - (Optional) URI and SAS token for a blob container to store backups. + * `enable_power_bi_service` - (Optional) Indicates if the Power BI service is allowed to access or not. * `ipv4_firewall_rule` - (Optional) One or more `ipv4_firewall_rule` block(s) as defined below. From d3692336ec1b4e344a7ea18bbb3404236d3f19fa Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 19 Sep 2019 19:58:31 +0200 Subject: [PATCH 3/6] add test for backup_blob_container_uri (not working yet) --- ...ource_arm_analysis_services_server_test.go | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/azurerm/resource_arm_analysis_services_server_test.go b/azurerm/resource_arm_analysis_services_server_test.go index c488e70a570e..4776d27418b1 100644 --- a/azurerm/resource_arm_analysis_services_server_test.go +++ b/azurerm/resource_arm_analysis_services_server_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" @@ -217,6 +218,32 @@ func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { }) } +func TestAccAzureRMAnalysisServicesServer_backupBlobContainerUri(t *testing.T) { + resourceName := "azurerm_analysis_services_server.test" + ri := tf.AccRandTimeInt() + rs := acctest.RandString(6) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAnalysisServicesServerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(ri, testLocation(), rs), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAnalysisServicesServerExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "backup_blob_container_uri"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccAzureRMAnalysisServicesServer_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -393,6 +420,57 @@ resource "azurerm_analysis_services_server" "test" { `, rInt, location, rInt) } +func testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(rInt int, location string, rString string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestass%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_kind = "BlobStorage" + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_container" "test" { + name = "assbackup" + storage_account_name = "${azurerm_storage_account.test.name}" + container_access_type = "private" +} + +data "azurerm_storage_account_blob_container_sas" "test" { + connection_string = "${azurerm_storage_account.test.primary_connection_string}" + container_name = "${azurerm_storage_container.test.name}" + https_only = true + + start = "${timeadd(timestamp(), "-24h")}" + expiry = "${timeadd(timestamp(), "48h")}" + + permissions { + read = true + add = true + create = true + write = true + delete = true + list = true + } +} + +resource "azurerm_analysis_services_server" "test" { + name = "acctestass%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "B1" + + backup_blob_container_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}${data.azurerm_storage_account_blob_container_sas.test.sas}" +} +`, rInt, location, rString, rInt) +} + func testCheckAzureRMAnalysisServicesServerDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).analysisservices.ServerClient From ae5c99d6f927a9e0aeaa2fb0cb70581d9f30d261 Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 20 Sep 2019 11:09:24 +0200 Subject: [PATCH 4/6] fix not working test --- azurerm/resource_arm_analysis_services_server_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_analysis_services_server_test.go b/azurerm/resource_arm_analysis_services_server_test.go index 4776d27418b1..06de35fdb4e1 100644 --- a/azurerm/resource_arm_analysis_services_server_test.go +++ b/azurerm/resource_arm_analysis_services_server_test.go @@ -235,11 +235,6 @@ func TestAccAzureRMAnalysisServicesServer_backupBlobContainerUri(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "backup_blob_container_uri"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, }, }) } @@ -447,8 +442,8 @@ data "azurerm_storage_account_blob_container_sas" "test" { container_name = "${azurerm_storage_container.test.name}" https_only = true - start = "${timeadd(timestamp(), "-24h")}" - expiry = "${timeadd(timestamp(), "48h")}" + start = "2018-06-01" + expiry = "2048-06-01" permissions { read = true From 3b6117f9f8cea33daaed26cf24a3741b0b38ed07 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 26 Sep 2019 10:44:26 +0200 Subject: [PATCH 5/6] remove nil check for pointer to string Co-Authored-By: Tom Harvey --- azurerm/resource_arm_analysis_services_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_analysis_services_server.go b/azurerm/resource_arm_analysis_services_server.go index 5f2da5a37336..95c6686e9c5c 100644 --- a/azurerm/resource_arm_analysis_services_server.go +++ b/azurerm/resource_arm_analysis_services_server.go @@ -223,7 +223,7 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac if serverFullName := serverProps.ServerFullName; serverFullName != nil { d.Set("server_full_name", serverProps.ServerFullName) - } + d.Set("server_full_name", serverProps.ServerFullName) if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { d.Set("backup_blob_container_uri", containerUri) From 7f0eefab3a4ced2f2a092f5ab1e47b44c5a4ac28 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 26 Sep 2019 11:16:58 +0200 Subject: [PATCH 6/6] fix a problem with GitHb commit --- azurerm/resource_arm_analysis_services_server.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azurerm/resource_arm_analysis_services_server.go b/azurerm/resource_arm_analysis_services_server.go index 95c6686e9c5c..b46af3a64793 100644 --- a/azurerm/resource_arm_analysis_services_server.go +++ b/azurerm/resource_arm_analysis_services_server.go @@ -221,9 +221,7 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac d.Set("querypool_connection_mode", string(serverProps.QuerypoolConnectionMode)) - if serverFullName := serverProps.ServerFullName; serverFullName != nil { - d.Set("server_full_name", serverProps.ServerFullName) - d.Set("server_full_name", serverProps.ServerFullName) + d.Set("server_full_name", serverProps.ServerFullName) if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { d.Set("backup_blob_container_uri", containerUri)