From 21f6cc54e95d3808dd7f58ccf0a33c993eccdba9 Mon Sep 17 00:00:00 2001 From: yupwei Date: Fri, 3 Apr 2020 11:17:06 +0800 Subject: [PATCH 01/12] update --- .../services/containers/resource_arm_kubernetes_cluster.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go index bf1b4312903f..761ed02dba32 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go @@ -270,14 +270,12 @@ func resourceArmKubernetesCluster() *schema.Resource { "managed_outbound_ip_count": { Type: schema.TypeInt, Optional: true, - Computed: true, ValidateFunc: validation.IntBetween(1, 100), ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, }, "outbound_ip_prefix_ids": { Type: schema.TypeSet, Optional: true, - Computed: true, ConfigMode: schema.SchemaConfigModeAttr, ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.managed_outbound_ip_count", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, Elem: &schema.Schema{ @@ -288,7 +286,6 @@ func resourceArmKubernetesCluster() *schema.Resource { "outbound_ip_address_ids": { Type: schema.TypeSet, Optional: true, - Computed: true, ConfigMode: schema.SchemaConfigModeAttr, ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.managed_outbound_ip_count", "network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids"}, Elem: &schema.Schema{ From 523ba4ecdc2c7303231880d486c438da70490d6a Mon Sep 17 00:00:00 2001 From: yupwei Date: Wed, 22 Apr 2020 11:37:14 +0800 Subject: [PATCH 02/12] update --- .../services/containers/resource_arm_kubernetes_cluster.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go index 761ed02dba32..bf1b4312903f 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go @@ -270,12 +270,14 @@ func resourceArmKubernetesCluster() *schema.Resource { "managed_outbound_ip_count": { Type: schema.TypeInt, Optional: true, + Computed: true, ValidateFunc: validation.IntBetween(1, 100), ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, }, "outbound_ip_prefix_ids": { Type: schema.TypeSet, Optional: true, + Computed: true, ConfigMode: schema.SchemaConfigModeAttr, ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.managed_outbound_ip_count", "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"}, Elem: &schema.Schema{ @@ -286,6 +288,7 @@ func resourceArmKubernetesCluster() *schema.Resource { "outbound_ip_address_ids": { Type: schema.TypeSet, Optional: true, + Computed: true, ConfigMode: schema.SchemaConfigModeAttr, ConflictsWith: []string{"network_profile.0.load_balancer_profile.0.managed_outbound_ip_count", "network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids"}, Elem: &schema.Schema{ From 53178292dbfc05ba4386d90b48c55df898ebf12e Mon Sep 17 00:00:00 2001 From: yupwei Date: Fri, 3 Apr 2020 11:17:06 +0800 Subject: [PATCH 03/12] update --- azurerm/internal/clients/client.go | 1 - .../data_source_data_share_accounts.go | 82 ++++++ .../datashare/parse/data_share_account.go | 30 +++ .../parse/data_share_account_test.go | 72 ++++++ .../resource_arm_data_share_accounts.go | 239 ++++++++++++++++++ .../data_source_data_share_accounts_test.go | 35 +++ .../resource_arm_data_share_accounts_test.go | 202 +++++++++++++++ .../datashare/datashareapi/interfaces.go | 164 ++++++++++++ .../docs/d/data_share_accounts.html.markdown | 48 ++++ .../docs/r/data_share_accounts.html.markdown | 75 ++++++ 10 files changed, 947 insertions(+), 1 deletion(-) create mode 100644 azurerm/internal/services/datashare/data_source_data_share_accounts.go create mode 100644 azurerm/internal/services/datashare/parse/data_share_account.go create mode 100644 azurerm/internal/services/datashare/parse/data_share_account_test.go create mode 100644 azurerm/internal/services/datashare/resource_arm_data_share_accounts.go create mode 100644 azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go create mode 100644 azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go create mode 100644 website/docs/d/data_share_accounts.html.markdown create mode 100644 website/docs/r/data_share_accounts.html.markdown diff --git a/azurerm/internal/clients/client.go b/azurerm/internal/clients/client.go index fe72c41e485e..6b6c6f7e1868 100644 --- a/azurerm/internal/clients/client.go +++ b/azurerm/internal/clients/client.go @@ -2,7 +2,6 @@ package clients import ( "context" - "github.com/Azure/go-autorest/autorest" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" diff --git a/azurerm/internal/services/datashare/data_source_data_share_accounts.go b/azurerm/internal/services/datashare/data_source_data_share_accounts.go new file mode 100644 index 000000000000..cce7ac79661e --- /dev/null +++ b/azurerm/internal/services/datashare/data_source_data_share_accounts.go @@ -0,0 +1,82 @@ +package datashare + +import ( + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceDataShareAccount() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmDataShareAccountRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "location": azure.SchemaLocationForDataSource(), + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "created_at": { + Type: schema.TypeString, + Computed: true, + }, + "user_email": { + Type: schema.TypeString, + Computed: true, + }, + "user_name": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.AccountClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if id := resp.ID; id != nil { + d.SetId(*resp.ID) + } + d.Set("resource_group_name", resourceGroup) + d.Set("name", name) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + if name := resp.Name; name != nil { + d.Set("name", name) + } + if props := resp.AccountProperties; props != nil { + d.Set("created_at", props.CreatedAt.Format(time.RFC3339)) + d.Set("user_email", props.UserEmail) + d.Set("user_name", props.UserName) + } + return nil +} diff --git a/azurerm/internal/services/datashare/parse/data_share_account.go b/azurerm/internal/services/datashare/parse/data_share_account.go new file mode 100644 index 000000000000..64f37a89efc4 --- /dev/null +++ b/azurerm/internal/services/datashare/parse/data_share_account.go @@ -0,0 +1,30 @@ +package parse + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DataShareAccountId struct { + ResourceGroup string + Name string +} + +func DataShareAccountID(input string) (*DataShareAccountId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("Unable to parse DataShareAccount ID %q: %+v", input, err) + } + + dataShareAccount := DataShareAccountId{ + ResourceGroup: id.ResourceGroup, + } + if dataShareAccount.Name, err = id.PopSegment("accounts"); err != nil { + return nil, err + } + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &dataShareAccount, nil +} diff --git a/azurerm/internal/services/datashare/parse/data_share_account_test.go b/azurerm/internal/services/datashare/parse/data_share_account_test.go new file mode 100644 index 000000000000..23603fa0456d --- /dev/null +++ b/azurerm/internal/services/datashare/parse/data_share_account_test.go @@ -0,0 +1,72 @@ +package parse + +import ( + "testing" +) + +func TestDataShareAccountID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DataShareAccountId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/", + Expected: nil, + }, + { + Name: "Datashare account ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1", + Expected: &DataShareAccountId{ + Name: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/Accounts/account1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q..", v.Name) + + actual, err := DataShareAccountID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go b/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go new file mode 100644 index 000000000000..76714cfcec18 --- /dev/null +++ b/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go @@ -0,0 +1,239 @@ +package datashare + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/structure" + "github.com/hashicorp/terraform-plugin-sdk/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/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDataShareAccount() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataShareAccountCreate, + Read: resourceArmDataShareAccountRead, + Update: resourceArmDataShareAccountUpdate, + Delete: resourceArmDataShareAccountDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DataShareAccountID(id) + return err + }), + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "location": azure.SchemaLocation(), + "resource_group_name": azure.SchemaResourceGroupName(), + "created_at": { + Type: schema.TypeString, + Computed: true, + }, + "user_email": { + Type: schema.TypeString, + Computed: true, + }, + "user_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "Accepted", + "InProgress", + "TransientFailure", + "Succeeded", + "Failed", + "Canceled", + }, false), + }, + "end_time": { + Type: schema.TypeString, + Optional: true, + }, + "error": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": { + Type: schema.TypeString, + Required: true, + }, + "message": { + Type: schema.TypeString, + Required: true, + }, + "data_share_error_info_details": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsJSON, + DiffSuppressFunc: structure.SuppressJsonDiff, + }, + "target": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "start_time": { + Type: schema.TypeString, + Optional: true, + }, + "tags": tags.Schema(), + }, + } +} +func resourceArmDataShareAccountCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.AccountClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for present of existing DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_data_share_account", *existing.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + t := d.Get("tags").(map[string]interface{}) + + account := datashare.Account{ + Location: utils.String(location), + Tags: tags.Expand(t), + } + + props := datashare.AccountProperties{} + account.AccountProperties = &props + if _, err := client.Create(ctx, resourceGroup, name, account); err != nil { + return fmt.Errorf("Error creating/updating DataShare Account %q (Resource Group %q / account %q): %+v", name, resourceGroup, account, err) + } + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + return resourceArmDataShareAccountRead(d, meta) +} + +func resourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.AccountClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DataShareAccountID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.Name) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + if name := resp.Name; name != nil { + d.Set("name", name) + } + if props := resp.AccountProperties; props != nil { + d.Set("created_at", props.CreatedAt.Format(time.RFC3339)) + d.Set("user_email", props.UserEmail) + d.Set("user_name", props.UserName) + } + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmDataShareAccountUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.AccountClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + t := d.Get("tags").(map[string]interface{}) + + accountUpdateParameters := datashare.AccountUpdateParameters{ + Tags: tags.Expand(t), + } + + if _, err := client.Update(ctx, resourceGroup, name, accountUpdateParameters); err != nil { + return fmt.Errorf("Error creating/updating DataShare Account %q (Resource Group %q / accountUpdateParameters %q): %+v", name, resourceGroup, accountUpdateParameters, err) + } + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil { + return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + return resourceArmDataShareAccountRead(d, meta) +} + +func resourceArmDataShareAccountDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.AccountClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DataShareAccountID(d.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, id.ResourceGroup, id.Name); err != nil { + return fmt.Errorf("Error deleting DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + return nil +} diff --git a/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go new file mode 100644 index 000000000000..f86e3f933d90 --- /dev/null +++ b/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go @@ -0,0 +1,35 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMDataShareAccount_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_data_share_account", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceDataShareAccount_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareAccountExists(data.ResourceName), + ), + }, + }, + }) +} + +func testAccDataSourceDataShareAccount_basic(data acceptance.TestData) string { + config := testAccAzureRMDataShareAccount_basic(data) + return fmt.Sprintf(` +%s +data "azurerm_data_shareaccount" "test" { +} +`, config) +} diff --git a/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go new file mode 100644 index 000000000000..6737e93d5d19 --- /dev/null +++ b/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go @@ -0,0 +1,202 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDataShareAccount_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShareAccount_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataShareAccount_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShareAccount_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + ), + }, + { + Config: testAccAzureRMDataShareAccount_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_data_share_account"), + }, + }, + }) +} + +func TestAccAzureRMDataShareAccount_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShareAccount_complete(data), + Check: resource.ComposeTestCheckFunc(), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataShareAccount_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShareAccount_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShareAccount_complete(data), + Check: resource.ComposeTestCheckFunc(), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMDataShareAccountExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.AccountClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("DataShare Account not found: %s", resourceName) + + } + id, err := parse.DataShareAccountID(rs.Primary.ID) + if err != nil { + return err + } + if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: data_share account %q does not exist", id.Name) + } + return fmt.Errorf("Bad: Get on DataShareAccountClient: %+v", err) + } + return nil + } +} + +func testCheckAzureRMDataShareAccountDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.AccountClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_share_account" { + continue + } + id, err := parse.DataShareAccountID(rs.Primary.ID) + if err != nil { + return err + } + if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on data_share.accountClient: %+v", err) + } + } + return nil + } + return nil +} + +func testAccAzureRMDataShareAccount_basic(data acceptance.TestData) string { + template := testAccAzureRMDataShareAccount_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share_account" "test" { + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tags = { + ENV = "Test" + } +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDataShareAccount_requiresImport(data acceptance.TestData) string { + config := testAccAzureRMDataShareAccount_basic(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share_account" "import" { + name = azurerm_data_share_account.test.name + location = azurerm_data_share_account.test.location + resource_group_name = azurerm_data_share_account.test.resource_group_name + tags = azurerm_data_share_account.test.tags +} +`, config) +} + +func testAccAzureRMDataShareAccount_complete(data acceptance.TestData) string { + template := testAccAzureRMDataShareAccount_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share_account" "test" { + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tags = { + ENV = "Test" + } +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDataShareAccount_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go b/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go new file mode 100644 index 000000000000..b7d296dec725 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go @@ -0,0 +1,164 @@ +package datashareapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" + "github.com/Azure/go-autorest/autorest" +) + +// AccountsClientAPI contains the set of methods on the AccountsClient type. +type AccountsClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, account datashare.Account) (result datashare.AccountsCreateFuture, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string) (result datashare.AccountsDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string) (result datashare.Account, err error) + ListByResourceGroup(ctx context.Context, resourceGroupName string, skipToken string) (result datashare.AccountListPage, err error) + ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, skipToken string) (result datashare.AccountListIterator, err error) + ListBySubscription(ctx context.Context, skipToken string) (result datashare.AccountListPage, err error) + ListBySubscriptionComplete(ctx context.Context, skipToken string) (result datashare.AccountListIterator, err error) + Update(ctx context.Context, resourceGroupName string, accountName string, accountUpdateParameters datashare.AccountUpdateParameters) (result datashare.Account, err error) +} + +var _ AccountsClientAPI = (*datashare.AccountsClient)(nil) + +// ConsumerInvitationsClientAPI contains the set of methods on the ConsumerInvitationsClient type. +type ConsumerInvitationsClientAPI interface { + Get(ctx context.Context, location string, invitationID string) (result datashare.ConsumerInvitation, err error) + ListInvitations(ctx context.Context, skipToken string) (result datashare.ConsumerInvitationListPage, err error) + ListInvitationsComplete(ctx context.Context, skipToken string) (result datashare.ConsumerInvitationListIterator, err error) + RejectInvitation(ctx context.Context, location string, invitation datashare.ConsumerInvitation) (result datashare.ConsumerInvitation, err error) +} + +var _ ConsumerInvitationsClientAPI = (*datashare.ConsumerInvitationsClient)(nil) + +// DataSetsClientAPI contains the set of methods on the DataSetsClient type. +type DataSetsClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string, dataSet datashare.BasicDataSet) (result datashare.DataSetModel, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result datashare.DataSetsDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result datashare.DataSetModel, err error) + ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.DataSetListPage, err error) + ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.DataSetListIterator, err error) +} + +var _ DataSetsClientAPI = (*datashare.DataSetsClient)(nil) + +// DataSetMappingsClientAPI contains the set of methods on the DataSetMappingsClient type. +type DataSetMappingsClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string, dataSetMapping datashare.BasicDataSetMapping) (result datashare.DataSetMappingModel, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string) (result autorest.Response, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string) (result datashare.DataSetMappingModel, err error) + ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.DataSetMappingListPage, err error) + ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.DataSetMappingListIterator, err error) +} + +var _ DataSetMappingsClientAPI = (*datashare.DataSetMappingsClient)(nil) + +// InvitationsClientAPI contains the set of methods on the InvitationsClient type. +type InvitationsClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string, invitation datashare.Invitation) (result datashare.Invitation, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string) (result autorest.Response, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string) (result datashare.Invitation, err error) + ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.InvitationListPage, err error) + ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.InvitationListIterator, err error) +} + +var _ InvitationsClientAPI = (*datashare.InvitationsClient)(nil) + +// OperationsClientAPI contains the set of methods on the OperationsClient type. +type OperationsClientAPI interface { + List(ctx context.Context) (result datashare.OperationListPage, err error) + ListComplete(ctx context.Context) (result datashare.OperationListIterator, err error) +} + +var _ OperationsClientAPI = (*datashare.OperationsClient)(nil) + +// SharesClientAPI contains the set of methods on the SharesClient type. +type SharesClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, share datashare.Share) (result datashare.Share, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string) (result datashare.SharesDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareName string) (result datashare.Share, err error) + ListByAccount(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareListPage, err error) + ListByAccountComplete(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareListIterator, err error) + ListSynchronizationDetails(ctx context.Context, resourceGroupName string, accountName string, shareName string, shareSynchronization datashare.ShareSynchronization, skipToken string) (result datashare.SynchronizationDetailsListPage, err error) + ListSynchronizationDetailsComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, shareSynchronization datashare.ShareSynchronization, skipToken string) (result datashare.SynchronizationDetailsListIterator, err error) + ListSynchronizations(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ShareSynchronizationListPage, err error) + ListSynchronizationsComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ShareSynchronizationListIterator, err error) +} + +var _ SharesClientAPI = (*datashare.SharesClient)(nil) + +// ProviderShareSubscriptionsClientAPI contains the set of methods on the ProviderShareSubscriptionsClient type. +type ProviderShareSubscriptionsClientAPI interface { + GetByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscription, err error) + ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ProviderShareSubscriptionListPage, err error) + ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ProviderShareSubscriptionListIterator, err error) + Reinstate(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscription, err error) + Revoke(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscriptionsRevokeFuture, err error) +} + +var _ ProviderShareSubscriptionsClientAPI = (*datashare.ProviderShareSubscriptionsClient)(nil) + +// ShareSubscriptionsClientAPI contains the set of methods on the ShareSubscriptionsClient type. +type ShareSubscriptionsClientAPI interface { + CancelSynchronization(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization) (result datashare.ShareSubscriptionsCancelSynchronizationFuture, err error) + Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscription datashare.ShareSubscription) (result datashare.ShareSubscription, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string) (result datashare.ShareSubscriptionsDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string) (result datashare.ShareSubscription, err error) + ListByAccount(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareSubscriptionListPage, err error) + ListByAccountComplete(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareSubscriptionListIterator, err error) + ListSourceShareSynchronizationSettings(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.SourceShareSynchronizationSettingListPage, err error) + ListSourceShareSynchronizationSettingsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.SourceShareSynchronizationSettingListIterator, err error) + ListSynchronizationDetails(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization, skipToken string) (result datashare.SynchronizationDetailsListPage, err error) + ListSynchronizationDetailsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization, skipToken string) (result datashare.SynchronizationDetailsListIterator, err error) + ListSynchronizations(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ShareSubscriptionSynchronizationListPage, err error) + ListSynchronizationsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ShareSubscriptionSynchronizationListIterator, err error) + SynchronizeMethod(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, synchronize datashare.Synchronize) (result datashare.ShareSubscriptionsSynchronizeMethodFuture, err error) +} + +var _ ShareSubscriptionsClientAPI = (*datashare.ShareSubscriptionsClient)(nil) + +// ConsumerSourceDataSetsClientAPI contains the set of methods on the ConsumerSourceDataSetsClient type. +type ConsumerSourceDataSetsClientAPI interface { + ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ConsumerSourceDataSetListPage, err error) + ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ConsumerSourceDataSetListIterator, err error) +} + +var _ ConsumerSourceDataSetsClientAPI = (*datashare.ConsumerSourceDataSetsClient)(nil) + +// SynchronizationSettingsClientAPI contains the set of methods on the SynchronizationSettingsClient type. +type SynchronizationSettingsClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string, synchronizationSetting datashare.BasicSynchronizationSetting) (result datashare.SynchronizationSettingModel, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string) (result datashare.SynchronizationSettingsDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string) (result datashare.SynchronizationSettingModel, err error) + ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.SynchronizationSettingListPage, err error) + ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.SynchronizationSettingListIterator, err error) +} + +var _ SynchronizationSettingsClientAPI = (*datashare.SynchronizationSettingsClient)(nil) + +// TriggersClientAPI contains the set of methods on the TriggersClient type. +type TriggersClientAPI interface { + Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string, trigger datashare.BasicTrigger) (result datashare.TriggersCreateFuture, err error) + Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string) (result datashare.TriggersDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string) (result datashare.TriggerModel, err error) + ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.TriggerListPage, err error) + ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.TriggerListIterator, err error) +} + +var _ TriggersClientAPI = (*datashare.TriggersClient)(nil) diff --git a/website/docs/d/data_share_accounts.html.markdown b/website/docs/d/data_share_accounts.html.markdown new file mode 100644 index 000000000000..374a59ca877b --- /dev/null +++ b/website/docs/d/data_share_accounts.html.markdown @@ -0,0 +1,48 @@ +--- +subcategory: "DataShare" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_share_account" +description: |- + Gets information about an existing DataShare Account +--- + +# Data Source: azurerm_data_share_account + +Uses this data source to access information about an existing DataShare Account +--- + +## DataShare Account Usage + +```hcl +data "azurerm_data_share_account" "example" { + name = "example-account" + resource_group_name = "example-resource-group" + +output "data_share_account_id" { + value = data.azurerm_data_share_account.example.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the DataShare Account. + +* `resource_group_name` - (Required) Specifies the name of the resource group the DataShare Account is located in. + +## Attributes Reference + +The following attributes are exported: + +* `name` - Specifies the name of the DataShare Account. + +* `id` - The ID of DataShare Account. + +## Timeouts + +~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. \ No newline at end of file diff --git a/website/docs/r/data_share_accounts.html.markdown b/website/docs/r/data_share_accounts.html.markdown new file mode 100644 index 000000000000..4cd3a8f668cf --- /dev/null +++ b/website/docs/r/data_share_accounts.html.markdown @@ -0,0 +1,75 @@ +--- +subcategory: "DataShare" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_share_account" +description: |- + Manages a DataShare Account +--- + +# azurerm_data_share_account + +Manages a DataShare Account + +~> **NOTE:** Azure allows only one active directory can be joined to a single subscription at a time for DataShare Account. + +## DataShare Account Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_data_share_account" "example" { + name = "example-dsa" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + tags = { + foo = "bar" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the DataShare Account. Changing this forces a new resource to be created. + +* `location` - (Required) The Azure location where the DataShare Account should exist. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group in which the DataShare Account should exist. Changing this forces a new resource to be created. + +* `created_at` - (Optional) Time at which the account was created. + +* `user_email` - (Optional) Email of the user who created the resource. + +* `user_name` - (Optional) Name of the user who created the resource. + +* `tags` - (Required) Tags on the azure resource. Changing this forces a new resource to be created. +--- + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Resource ID of the DataShare Account. + +## Timeouts + +~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the DataShare Account. +* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. +* `update` - (Defaults to 30 minutes) Used when updating the DataShare Account. +* `delete` - (Defaults to 30 minutes) Used when deleting the DataShare Account. + +## Import + +DataShare Account can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_data_share_account.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DataShare/accounts/account1 +``` \ No newline at end of file From e453f34e267615a7a4bb533a16d755a80c7f5cc2 Mon Sep 17 00:00:00 2001 From: yupwei Date: Fri, 3 Apr 2020 15:29:53 +0800 Subject: [PATCH 04/12] main update --- .../data_source_data_share_accounts.go | 43 ++--- .../datashare/parse/data_share_account.go | 1 + .../parse/data_share_account_test.go | 2 +- .../resource_arm_data_share_accounts.go | 151 ++++++------------ .../data_source_data_share_accounts_test.go | 6 +- .../resource_arm_data_share_accounts_test.go | 93 +++++------ .../services/datashare/validate/dataShare.go | 38 +++++ .../docs/d/data_share_accounts.html.markdown | 97 +++++------ .../docs/r/data_share_accounts.html.markdown | 128 +++++++-------- 9 files changed, 268 insertions(+), 291 deletions(-) create mode 100644 azurerm/internal/services/datashare/validate/dataShare.go diff --git a/azurerm/internal/services/datashare/data_source_data_share_accounts.go b/azurerm/internal/services/datashare/data_source_data_share_accounts.go index cce7ac79661e..9ae8de6d63e8 100644 --- a/azurerm/internal/services/datashare/data_source_data_share_accounts.go +++ b/azurerm/internal/services/datashare/data_source_data_share_accounts.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -26,20 +27,11 @@ func dataSourceDataShareAccount() *schema.Resource { Type: schema.TypeString, Required: true, }, - "location": azure.SchemaLocationForDataSource(), + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), - "created_at": { - Type: schema.TypeString, - Computed: true, - }, - "user_email": { - Type: schema.TypeString, - Computed: true, - }, - "user_name": { - Type: schema.TypeString, - Computed: true, - }, + + "location": azure.SchemaLocationForDataSource(), + "tags": tags.SchemaDataSource(), }, } @@ -50,33 +42,28 @@ func dataSourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id, err := parse.DataShareAccountID(d.Id()) + if err != nil { + return err + } - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if id := resp.ID; id != nil { d.SetId(*resp.ID) } - d.Set("resource_group_name", resourceGroup) - d.Set("name", name) + + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } - if name := resp.Name; name != nil { - d.Set("name", name) - } - if props := resp.AccountProperties; props != nil { - d.Set("created_at", props.CreatedAt.Format(time.RFC3339)) - d.Set("user_email", props.UserEmail) - d.Set("user_name", props.UserName) - } - return nil + return tags.FlattenAndSet(d, resp.Tags) } diff --git a/azurerm/internal/services/datashare/parse/data_share_account.go b/azurerm/internal/services/datashare/parse/data_share_account.go index 64f37a89efc4..b053da3473d4 100644 --- a/azurerm/internal/services/datashare/parse/data_share_account.go +++ b/azurerm/internal/services/datashare/parse/data_share_account.go @@ -2,6 +2,7 @@ package parse import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) diff --git a/azurerm/internal/services/datashare/parse/data_share_account_test.go b/azurerm/internal/services/datashare/parse/data_share_account_test.go index 23603fa0456d..3c14595b2d91 100644 --- a/azurerm/internal/services/datashare/parse/data_share_account_test.go +++ b/azurerm/internal/services/datashare/parse/data_share_account_test.go @@ -37,7 +37,7 @@ func TestDataShareAccountID(t *testing.T) { }, { Name: "Datashare account ID", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1", Expected: &DataShareAccountId{ Name: "account1", ResourceGroup: "resGroup1", diff --git a/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go b/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go index 76714cfcec18..cea24089394a 100644 --- a/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go +++ b/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go @@ -2,13 +2,13 @@ package datashare import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate" "log" "time" "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" + "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/structure" - "github.com/hashicorp/terraform-plugin-sdk/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/internal/clients" @@ -45,68 +45,20 @@ func resourceArmDataShareAccount() *schema.Resource { Required: true, ForceNew: true, }, - "location": azure.SchemaLocation(), + "resource_group_name": azure.SchemaResourceGroupName(), - "created_at": { - Type: schema.TypeString, - Computed: true, - }, - "user_email": { - Type: schema.TypeString, - Computed: true, - }, - "user_name": { - Type: schema.TypeString, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "Accepted", - "InProgress", - "TransientFailure", - "Succeeded", - "Failed", - "Canceled", - }, false), - }, - "end_time": { - Type: schema.TypeString, - Optional: true, - }, - "error": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "code": { - Type: schema.TypeString, - Required: true, - }, - "message": { - Type: schema.TypeString, - Required: true, - }, - "data_share_error_info_details": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringIsJSON, - DiffSuppressFunc: structure.SuppressJsonDiff, - }, - "target": { - Type: schema.TypeString, - Optional: true, - }, - }, + + "location": azure.SchemaLocation(), + + // the api will save and return the tag keys in lowercase, so an extra validation of the key is all in lowercase is added + "tags": { + Type: schema.TypeMap, + Optional: true, + ValidateFunc: validate.DatashareTags, + Elem: &schema.Schema{ + Type: schema.TypeString, }, }, - "start_time": { - Type: schema.TypeString, - Optional: true, - }, - "tags": tags.Schema(), }, } } @@ -115,14 +67,14 @@ func resourceArmDataShareAccountCreate(d *schema.ResourceData, meta interface{}) ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for present of existing DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Failure in checking for present of existing DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } } if existing.ID != nil && *existing.ID != "" { @@ -130,27 +82,31 @@ func resourceArmDataShareAccountCreate(d *schema.ResourceData, meta interface{}) } } - location := azure.NormalizeLocation(d.Get("location").(string)) - t := d.Get("tags").(map[string]interface{}) + accountProps := datashare.Account{ + Identity: &datashare.Identity{ + Type: "SystemAssigned", + }, + Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), + Name: utils.String(name), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + } - account := datashare.Account{ - Location: utils.String(location), - Tags: tags.Expand(t), + future, err := client.Create(ctx, resourceGroup, name, accountProps) + if err != nil { + return fmt.Errorf("Failure in creating DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } - props := datashare.AccountProperties{} - account.AccountProperties = &props - if _, err := client.Create(ctx, resourceGroup, name, account); err != nil { - return fmt.Errorf("Error creating/updating DataShare Account %q (Resource Group %q / account %q): %+v", name, resourceGroup, account, err) + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Failure in waiting on creating future for DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } resp, err := client.Get(ctx, resourceGroup, name) if err != nil { - return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } d.SetId(*resp.ID) @@ -174,21 +130,13 @@ func resourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.Set("resource_group_name", id.ResourceGroup) d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } - if name := resp.Name; name != nil { - d.Set("name", name) - } - if props := resp.AccountProperties; props != nil { - d.Set("created_at", props.CreatedAt.Format(time.RFC3339)) - d.Set("user_email", props.UserEmail) - d.Set("user_name", props.UserName) - } return tags.FlattenAndSet(d, resp.Tags) } @@ -197,28 +145,24 @@ func resourceArmDataShareAccountUpdate(d *schema.ResourceData, meta interface{}) ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) - t := d.Get("tags").(map[string]interface{}) - - accountUpdateParameters := datashare.AccountUpdateParameters{ - Tags: tags.Expand(t), + if !d.HasChange("tags") { + return nil } - if _, err := client.Update(ctx, resourceGroup, name, accountUpdateParameters); err != nil { - return fmt.Errorf("Error creating/updating DataShare Account %q (Resource Group %q / accountUpdateParameters %q): %+v", name, resourceGroup, accountUpdateParameters, err) + id, err := parse.DataShareAccountID(d.Id()) + if err != nil { + return err } - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Error retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + props := datashare.AccountUpdateParameters{ + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } - if resp.ID == nil { - return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) + _, err = client.Update(ctx, id.ResourceGroup, id.Name, props) + if err != nil { + return fmt.Errorf("Failure in issuing update request for DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.SetId(*resp.ID) return resourceArmDataShareAccountRead(d, meta) } @@ -232,8 +176,15 @@ func resourceArmDataShareAccountDelete(d *schema.ResourceData, meta interface{}) return err } - if _, err := client.Delete(ctx, id.ResourceGroup, id.Name); err != nil { - return fmt.Errorf("Error deleting DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + future, err := client.Delete(ctx, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("Failure in deleting DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Failure in waiting for DataShare Account %q (Resource Group %q) to be deleted: %+v", id.Name, id.ResourceGroup, err) + } } return nil } diff --git a/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go index f86e3f933d90..7e01ff0ec375 100644 --- a/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go +++ b/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go @@ -19,6 +19,8 @@ func TestAccDataSourceAzureRMDataShareAccount_basic(t *testing.T) { Config: testAccDataSourceDataShareAccount_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMDataShareAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Test"), ), }, }, @@ -26,10 +28,12 @@ func TestAccDataSourceAzureRMDataShareAccount_basic(t *testing.T) { } func testAccDataSourceDataShareAccount_basic(data acceptance.TestData) string { - config := testAccAzureRMDataShareAccount_basic(data) + config := testAccAzureRMDataShareAccount_complete(data) return fmt.Sprintf(` %s data "azurerm_data_shareaccount" "test" { + name = azurerm_data_share_account.test.name + resource_group_name = azurerm_resource_group.test.name } `, config) } diff --git a/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go index 6737e93d5d19..d9ce0d91e149 100644 --- a/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go +++ b/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go @@ -16,7 +16,7 @@ import ( func TestAccAzureRMDataShareAccount_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMDataShareAccountDestroy, @@ -24,8 +24,7 @@ func TestAccAzureRMDataShareAccount_basic(t *testing.T) { { Config: testAccAzureRMDataShareAccount_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + testCheckAzureRMDataShareAccountExists(data.ResourceName), ), }, data.ImportStep(), @@ -47,8 +46,7 @@ func TestAccAzureRMDataShareAccount_requiresImport(t *testing.T) { { Config: testAccAzureRMDataShareAccount_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + testCheckAzureRMDataShareAccountExists(data.ResourceName), ), }, { @@ -69,32 +67,20 @@ func TestAccAzureRMDataShareAccount_complete(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMDataShareAccount_complete(data), - Check: resource.ComposeTestCheckFunc(), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMDataShareAccount_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataShareAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDataShareAccount_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "tags.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + testCheckAzureRMDataShareAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Test"), ), }, data.ImportStep(), { - Config: testAccAzureRMDataShareAccount_complete(data), - Check: resource.ComposeTestCheckFunc(), + Config: testAccAzureRMDataShareAccount_update(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Stage"), + ), }, data.ImportStep(), }, @@ -146,17 +132,27 @@ func testCheckAzureRMDataShareAccountDestroy(s *terraform.State) error { return nil } +func testAccAzureRMDataShareAccount_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctest-datashare-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} + func testAccAzureRMDataShareAccount_basic(data acceptance.TestData) string { template := testAccAzureRMDataShareAccount_template(data) return fmt.Sprintf(` %s + resource "azurerm_data_share_account" "test" { - name = "acctest-dsa-%d" - location = azurerm_resource_group.test.location + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name - tags = { - ENV = "Test" - } } `, template, data.RandomInteger) } @@ -165,11 +161,11 @@ func testAccAzureRMDataShareAccount_requiresImport(data acceptance.TestData) str config := testAccAzureRMDataShareAccount_basic(data) return fmt.Sprintf(` %s + resource "azurerm_data_share_account" "import" { - name = azurerm_data_share_account.test.name - location = azurerm_data_share_account.test.location - resource_group_name = azurerm_data_share_account.test.resource_group_name - tags = azurerm_data_share_account.test.tags + name = azurerm_data_share_account.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, config) } @@ -178,25 +174,30 @@ func testAccAzureRMDataShareAccount_complete(data acceptance.TestData) string { template := testAccAzureRMDataShareAccount_template(data) return fmt.Sprintf(` %s + resource "azurerm_data_share_account" "test" { - name = "acctest-dsa-%d" - location = azurerm_resource_group.test.location + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name tags = { - ENV = "Test" + env = "Test" } } `, template, data.RandomInteger) } -func testAccAzureRMDataShareAccount_template(data acceptance.TestData) string { +func testAccAzureRMDataShareAccount_update(data acceptance.TestData) string { + template := testAccAzureRMDataShareAccount_template(data) return fmt.Sprintf(` -provider "azurerm" { - features {} -} -resource "azurerm_resource_group" "test" { - name = "acctest-rg-%d" - location = "%s" +%s + +resource "azurerm_data_share_account" "test" { + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tags = { + env = "Stage" + } } -`, data.RandomInteger, data.Locations.Primary) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/datashare/validate/dataShare.go b/azurerm/internal/services/datashare/validate/dataShare.go new file mode 100644 index 000000000000..06b0cb7c2421 --- /dev/null +++ b/azurerm/internal/services/datashare/validate/dataShare.go @@ -0,0 +1,38 @@ +package validate + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "strings" +) + +func DatashareTags(i interface{}, k string) (warnings []string, errors []error) { + tagsMap := i.(map[string]interface{}) + + if len(tagsMap) > 50 { + errors = append(errors, fmt.Errorf("a maximum of 50 tags can be applied to each ARM resource")) + } + + for k, v := range tagsMap { + if len(k) > 512 { + errors = append(errors, fmt.Errorf("the maximum length for a tag key is 512 characters: %q is %d characters", k, len(k))) + return warnings, errors + } + + if strings.ToLower(k) != k { + errors = append(errors, fmt.Errorf("a tag key %q expected to be all in lowercase", k)) + return warnings, errors + } + + value, err := tags.TagValueToString(v) + if err != nil { + errors = append(errors, err) + return warnings, errors + } else if len(value) > 256 { + errors = append(errors, fmt.Errorf("the maximum length for a tag value is 256 characters: the value for %q is %d characters", k, len(value))) + return warnings, errors + } + } + + return warnings, errors +} diff --git a/website/docs/d/data_share_accounts.html.markdown b/website/docs/d/data_share_accounts.html.markdown index 374a59ca877b..1947764186b4 100644 --- a/website/docs/d/data_share_accounts.html.markdown +++ b/website/docs/d/data_share_accounts.html.markdown @@ -1,48 +1,49 @@ ---- -subcategory: "DataShare" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_data_share_account" -description: |- - Gets information about an existing DataShare Account ---- - -# Data Source: azurerm_data_share_account - -Uses this data source to access information about an existing DataShare Account ---- - -## DataShare Account Usage - -```hcl -data "azurerm_data_share_account" "example" { - name = "example-account" - resource_group_name = "example-resource-group" - -output "data_share_account_id" { - value = data.azurerm_data_share_account.example.id -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) Specifies the name of the DataShare Account. - -* `resource_group_name` - (Required) Specifies the name of the resource group the DataShare Account is located in. - -## Attributes Reference - -The following attributes are exported: - -* `name` - Specifies the name of the DataShare Account. - -* `id` - The ID of DataShare Account. - -## Timeouts - -~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: - -* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. \ No newline at end of file +--- +subcategory: "DataShare" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_share_account" +description: |- + Gets information about an existing DataShare Account +--- + +# Data Source: azurerm_data_share_account + +Uses this data source to access information about an existing DataShare Account +--- + +## DataShare Account Usage + +```hcl +data "azurerm_data_share_account" "example" { + name = "example-account" + resource_group_name = "example-resource-group" +} + +output "data_share_account_id" { + value = data.azurerm_data_share_account.example.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the DataShare Account. + +* `resource_group_name` - (Required) Specifies the name of the resource group the DataShare Account is located in. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Data Share Account ID. + +* `tags` - A mapping of tags to assign to the resource. + +## Timeouts + +~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. diff --git a/website/docs/r/data_share_accounts.html.markdown b/website/docs/r/data_share_accounts.html.markdown index 4cd3a8f668cf..29eedcad6cc0 100644 --- a/website/docs/r/data_share_accounts.html.markdown +++ b/website/docs/r/data_share_accounts.html.markdown @@ -1,75 +1,69 @@ ---- -subcategory: "DataShare" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_data_share_account" -description: |- - Manages a DataShare Account ---- - -# azurerm_data_share_account - -Manages a DataShare Account - -~> **NOTE:** Azure allows only one active directory can be joined to a single subscription at a time for DataShare Account. - -## DataShare Account Usage - -```hcl +--- +subcategory: "DataShare" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_share_account" +description: |- + Manages a DataShare Account +--- + +# azurerm_data_share_account + +Manages a DataShare Account + +~> **NOTE:** Azure allows only one active directory can be joined to a single subscription at a time for DataShare Account. + +## DataShare Account Usage + +```hcl resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" -} - +} + resource "azurerm_data_share_account" "example" { - name = "example-dsa" - location = azurerm_resource_group.example.location + name = "example-dsa" + location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name tags = { foo = "bar" } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) The name of the DataShare Account. Changing this forces a new resource to be created. - -* `location` - (Required) The Azure location where the DataShare Account should exist. Changing this forces a new resource to be created. - -* `resource_group_name` - (Required) The name of the Resource Group in which the DataShare Account should exist. Changing this forces a new resource to be created. - -* `created_at` - (Optional) Time at which the account was created. - -* `user_email` - (Optional) Email of the user who created the resource. - -* `user_name` - (Optional) Name of the user who created the resource. - -* `tags` - (Required) Tags on the azure resource. Changing this forces a new resource to be created. ---- - -## Attributes Reference - -The following attributes are exported: - -* `id` - The Resource ID of the DataShare Account. - -## Timeouts - -~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: - -* `create` - (Defaults to 30 minutes) Used when creating the DataShare Account. -* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. -* `update` - (Defaults to 30 minutes) Used when updating the DataShare Account. -* `delete` - (Defaults to 30 minutes) Used when deleting the DataShare Account. - -## Import - -DataShare Account can be imported using the `resource id`, e.g. - -```shell -$ terraform import azurerm_data_share_account.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DataShare/accounts/account1 -``` \ No newline at end of file +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the DataShare Account. Changing this forces a new resource to be created. + +* `location` - (Required) The Azure location where the DataShare Account should exist. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group in which the DataShare Account should exist. Changing this forces a new resource to be created. + +* `tags` - (Optional) A mapping of tags to assign to the resource. +--- + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Resource ID of the DataShare Account. + +## Timeouts + +~> **Note:** Custom Timeouts are available [as an opt-in Beta in version 1.43 & 1.44 of the Azure Provider](/docs/providers/azurerm/guides/2.0-beta.html) and will be enabled by default in version 2.0 of the Azure Provider. + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the DataShare Account. +* `read` - (Defaults to 5 minutes) Used when retrieving the DataShare Account. +* `update` - (Defaults to 30 minutes) Used when updating the DataShare Account. +* `delete` - (Defaults to 30 minutes) Used when deleting the DataShare Account. + +## Import + +DataShare Account can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_data_share_account.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DataShare/accounts/account1 +``` From 67226e243eeee67ccb1bfddcc26eeb46cd4793e5 Mon Sep 17 00:00:00 2001 From: yupwei Date: Tue, 7 Apr 2020 10:20:27 +0800 Subject: [PATCH 05/12] update --- azurerm/internal/clients/client.go | 1 + .../services/datashare/client/client.go | 14 +- .../datashare/data_source_data_share.go | 124 +++++++ .../data_source_data_share_accounts.go | 69 ---- .../services/datashare/parse/data_share.go | 28 ++ .../datashare/parse/data_share_account.go | 31 -- .../parse/data_share_account_test.go | 72 ----- .../datashare/parse/data_share_test.go | 82 +++++ .../services/datashare/registration.go | 2 + .../datashare/resource_arm_data_share.go | 298 +++++++++++++++++ .../resource_arm_data_share_accounts.go | 190 ----------- .../data_source_data_share_accounts_test.go | 39 --- .../tests/data_source_data_share_test.go | 71 ++++ .../resource_arm_data_share_accounts_test.go | 203 ------------ .../tests/resource_arm_data_share_test.go | 303 ++++++++++++++++++ .../services/datashare/validate/dataShare.go | 38 --- .../services/datashare/validate/data_share.go | 22 ++ .../datashare/validate/data_share_test.go | 39 +++ .../datashare/datashareapi/interfaces.go | 164 ---------- website/azurerm.erb | 7 + website/docs/d/data_share.html.markdown | 69 ++++ .../docs/d/data_share_accounts.html.markdown | 49 --- website/docs/r/data_share.html.markdown | 93 ++++++ .../docs/r/data_share_accounts.html.markdown | 69 ---- 24 files changed, 1151 insertions(+), 926 deletions(-) create mode 100644 azurerm/internal/services/datashare/data_source_data_share.go delete mode 100644 azurerm/internal/services/datashare/data_source_data_share_accounts.go delete mode 100644 azurerm/internal/services/datashare/parse/data_share_account.go delete mode 100644 azurerm/internal/services/datashare/parse/data_share_account_test.go create mode 100644 azurerm/internal/services/datashare/resource_arm_data_share.go delete mode 100644 azurerm/internal/services/datashare/resource_arm_data_share_accounts.go delete mode 100644 azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go create mode 100644 azurerm/internal/services/datashare/tests/data_source_data_share_test.go delete mode 100644 azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go create mode 100644 azurerm/internal/services/datashare/tests/resource_arm_data_share_test.go delete mode 100644 azurerm/internal/services/datashare/validate/dataShare.go delete mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go create mode 100644 website/docs/d/data_share.html.markdown delete mode 100644 website/docs/d/data_share_accounts.html.markdown create mode 100644 website/docs/r/data_share.html.markdown delete mode 100644 website/docs/r/data_share_accounts.html.markdown diff --git a/azurerm/internal/clients/client.go b/azurerm/internal/clients/client.go index 6b6c6f7e1868..fe72c41e485e 100644 --- a/azurerm/internal/clients/client.go +++ b/azurerm/internal/clients/client.go @@ -2,6 +2,7 @@ package clients import ( "context" + "github.com/Azure/go-autorest/autorest" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" diff --git a/azurerm/internal/services/datashare/client/client.go b/azurerm/internal/services/datashare/client/client.go index 1292d3cfd94e..09bbc336a08c 100644 --- a/azurerm/internal/services/datashare/client/client.go +++ b/azurerm/internal/services/datashare/client/client.go @@ -6,14 +6,24 @@ import ( ) type Client struct { - AccountClient *datashare.AccountsClient + AccountClient *datashare.AccountsClient + SharesClient *datashare.SharesClient + SynchronizationClient *datashare.SynchronizationSettingsClient } func NewClient(o *common.ClientOptions) *Client { accountClient := datashare.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&accountClient.Client, o.ResourceManagerAuthorizer) + sharesClient := datashare.NewSharesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&sharesClient.Client, o.ResourceManagerAuthorizer) + + synchronizationSettingsClient := datashare.NewSynchronizationSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&synchronizationSettingsClient.Client, o.ResourceManagerAuthorizer) + return &Client{ - AccountClient: &accountClient, + AccountClient: &accountClient, + SharesClient: &sharesClient, + SynchronizationClient: &synchronizationSettingsClient, } } diff --git a/azurerm/internal/services/datashare/data_source_data_share.go b/azurerm/internal/services/datashare/data_source_data_share.go new file mode 100644 index 000000000000..82a4768dbd92 --- /dev/null +++ b/azurerm/internal/services/datashare/data_source_data_share.go @@ -0,0 +1,124 @@ +package datashare + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceDataShare() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmDataShareRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.DatashareName(), + }, + + "account_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.DatashareAccountID, + }, + + "share_kind": { + Type: schema.TypeString, + Computed: true, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + + "snapshot_schedule": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "recurrence": { + Type: schema.TypeString, + Computed: true, + }, + + "start_time": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "terms": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceArmDataShareRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.SharesClient + syncClient := meta.(*clients.Client).DataShare.SynchronizationClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + accountID := d.Get("account_id").(string) + accountId, err := parse.DataShareAccountID(accountID) + if err != nil { + return err + } + + resp, err := client.Get(ctx, accountId.ResourceGroup, accountId.Name, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("retrieving DataShare %q (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("reading DataShare %q (Resource Group %q / accountName %q): ID is empty", name, accountId.ResourceGroup, accountId.Name) + } + + d.SetId(*resp.ID) + d.Set("name", name) + d.Set("account_id", accountID) + if props := resp.ShareProperties; props != nil { + d.Set("share_kind", props.ShareKind) + d.Set("description", props.Description) + d.Set("terms", props.Terms) + } + + syncResp, err := syncClient.Get(ctx, accountId.ResourceGroup, accountId.Name, name, name) + if err != nil { + // if not found, we set nothing to the block + if !utils.ResponseWasNotFound(syncResp.Response) { + return fmt.Errorf("checking for present of existing DataShare %q snapshot schedule (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + } else { + if schedule := syncResp.Value.(datashare.ScheduledSynchronizationSetting); schedule.ID != nil && *schedule.ID != "" { + if err := d.Set("snapshot_schedule", flattenAzureRmDataShareSnapshotSchedule(&schedule)); err != nil { + return fmt.Errorf("setting `snapshot_schedule`: %+v", err) + } + } + } + return nil +} diff --git a/azurerm/internal/services/datashare/data_source_data_share_accounts.go b/azurerm/internal/services/datashare/data_source_data_share_accounts.go deleted file mode 100644 index 9ae8de6d63e8..000000000000 --- a/azurerm/internal/services/datashare/data_source_data_share_accounts.go +++ /dev/null @@ -1,69 +0,0 @@ -package datashare - -import ( - "fmt" - "log" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func dataSourceDataShareAccount() *schema.Resource { - return &schema.Resource{ - Read: dataSourceArmDataShareAccountRead, - - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), - - "location": azure.SchemaLocationForDataSource(), - - "tags": tags.SchemaDataSource(), - }, - } -} - -func dataSourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataShare.AccountClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := parse.DataShareAccountID(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - if id := resp.ID; id != nil { - d.SetId(*resp.ID) - } - - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - return tags.FlattenAndSet(d, resp.Tags) -} diff --git a/azurerm/internal/services/datashare/parse/data_share.go b/azurerm/internal/services/datashare/parse/data_share.go index 83bc7c3404a1..a9247a7b0da5 100644 --- a/azurerm/internal/services/datashare/parse/data_share.go +++ b/azurerm/internal/services/datashare/parse/data_share.go @@ -11,6 +11,12 @@ type DataShareAccountId struct { Name string } +type DataShareId struct { + ResourceGroup string + AccountName string + Name string +} + func DataShareAccountID(input string) (*DataShareAccountId, error) { id, err := azure.ParseAzureResourceID(input) if err != nil { @@ -29,3 +35,25 @@ func DataShareAccountID(input string) (*DataShareAccountId, error) { return &dataShareAccount, nil } + +func DataShareID(input string) (*DataShareId, error) { + var id, err = azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("unable to parse DataShare ID %q: %+v", input, err) + } + + DataShare := DataShareId{ + ResourceGroup: id.ResourceGroup, + } + if DataShare.AccountName, err = id.PopSegment("accounts"); err != nil { + return nil, err + } + if DataShare.Name, err = id.PopSegment("shares"); err != nil { + return nil, err + } + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &DataShare, nil +} diff --git a/azurerm/internal/services/datashare/parse/data_share_account.go b/azurerm/internal/services/datashare/parse/data_share_account.go deleted file mode 100644 index b053da3473d4..000000000000 --- a/azurerm/internal/services/datashare/parse/data_share_account.go +++ /dev/null @@ -1,31 +0,0 @@ -package parse - -import ( - "fmt" - - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" -) - -type DataShareAccountId struct { - ResourceGroup string - Name string -} - -func DataShareAccountID(input string) (*DataShareAccountId, error) { - id, err := azure.ParseAzureResourceID(input) - if err != nil { - return nil, fmt.Errorf("Unable to parse DataShareAccount ID %q: %+v", input, err) - } - - dataShareAccount := DataShareAccountId{ - ResourceGroup: id.ResourceGroup, - } - if dataShareAccount.Name, err = id.PopSegment("accounts"); err != nil { - return nil, err - } - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &dataShareAccount, nil -} diff --git a/azurerm/internal/services/datashare/parse/data_share_account_test.go b/azurerm/internal/services/datashare/parse/data_share_account_test.go deleted file mode 100644 index 3c14595b2d91..000000000000 --- a/azurerm/internal/services/datashare/parse/data_share_account_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package parse - -import ( - "testing" -) - -func TestDataShareAccountID(t *testing.T) { - testData := []struct { - Name string - Input string - Expected *DataShareAccountId - }{ - { - Name: "Empty", - Input: "", - Expected: nil, - }, - { - Name: "No Resource Groups Segment", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000", - Expected: nil, - }, - { - Name: "No Resource Groups Value", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", - Expected: nil, - }, - { - Name: "Resource Group ID", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", - Expected: nil, - }, - { - Name: "Missing Account Value", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/", - Expected: nil, - }, - { - Name: "Datashare account ID", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1", - Expected: &DataShareAccountId{ - Name: "account1", - ResourceGroup: "resGroup1", - }, - }, - { - Name: "Wrong Casing", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/Accounts/account1", - Expected: nil, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q..", v.Name) - - actual, err := DataShareAccountID(v.Input) - if err != nil { - if v.Expected == nil { - continue - } - t.Fatalf("Expected a value but got an error: %s", err) - } - - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) - } - - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/azurerm/internal/services/datashare/parse/data_share_test.go b/azurerm/internal/services/datashare/parse/data_share_test.go index 3c14595b2d91..fe1d4f3deca5 100644 --- a/azurerm/internal/services/datashare/parse/data_share_test.go +++ b/azurerm/internal/services/datashare/parse/data_share_test.go @@ -70,3 +70,85 @@ func TestDataShareAccountID(t *testing.T) { } } } + +func TestDataShareID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DataShareId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/", + Expected: nil, + }, + { + Name: "Missing Share", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1/", + Expected: nil, + }, + { + Name: "Missing Share Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1/shares/", + Expected: nil, + }, + { + Name: "Data Share ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1/shares/share1", + Expected: &DataShareId{ + Name: "share1", + AccountName: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DataShare/accounts/account1/Shares/share1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q..", v.Name) + + actual, err := DataShareID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for account name", v.Expected.AccountName, actual.AccountName) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/azurerm/internal/services/datashare/registration.go b/azurerm/internal/services/datashare/registration.go index 0ddb1dd85d4e..87cff3e1cbaa 100644 --- a/azurerm/internal/services/datashare/registration.go +++ b/azurerm/internal/services/datashare/registration.go @@ -20,6 +20,7 @@ func (r Registration) WebsiteCategories() []string { func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_data_share_account": dataSourceDataShareAccount(), + "azurerm_data_share": dataSourceDataShare(), } } @@ -27,5 +28,6 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_data_share_account": resourceArmDataShareAccount(), + "azurerm_data_share": resourceArmDataShare(), } } diff --git a/azurerm/internal/services/datashare/resource_arm_data_share.go b/azurerm/internal/services/datashare/resource_arm_data_share.go new file mode 100644 index 000000000000..5dd420581794 --- /dev/null +++ b/azurerm/internal/services/datashare/resource_arm_data_share.go @@ -0,0 +1,298 @@ +package datashare + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" + "github.com/Azure/go-autorest/autorest/date" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "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/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDataShare() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataShareCreateUpdate, + Read: resourceArmDataShareRead, + Update: resourceArmDataShareCreateUpdate, + Delete: resourceArmDataShareDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DataShareID(id) + return err + }), + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.DatashareName(), + }, + + "account_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.DatashareAccountID, + }, + + "share_kind": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(datashare.CopyBased), + string(datashare.InPlace), + }, false), + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "snapshot_schedule": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "recurrence": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(datashare.Day), + string(datashare.Hour), + }, false), + }, + + "start_time": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.IsRFC3339Time, + DiffSuppressFunc: suppress.RFC3339Time, + }, + }, + }, + }, + + "terms": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} +func resourceArmDataShareCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.SharesClient + syncClient := meta.(*clients.Client).DataShare.SynchronizationClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + accountId, err := parse.DataShareAccountID(d.Get("account_id").(string)) + if err != nil { + return err + } + + if d.IsNewResource() { + existing, err := client.Get(ctx, accountId.ResourceGroup, accountId.Name, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for present of existing DataShare %q (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + } + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_data_share", *existing.ID) + } + } + + share := datashare.Share{ + ShareProperties: &datashare.ShareProperties{ + ShareKind: datashare.ShareKind(d.Get("share_kind").(string)), + Description: utils.String(d.Get("description").(string)), + Terms: utils.String(d.Get("terms").(string)), + }, + } + + if _, err := client.Create(ctx, accountId.ResourceGroup, accountId.Name, name, share); err != nil { + return fmt.Errorf("creating DataShare %q (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + + resp, err := client.Get(ctx, accountId.ResourceGroup, accountId.Name, name) + if err != nil { + return fmt.Errorf("retrieving DataShare %q (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("reading DataShare %q (Resource Group %q / accountName %q): ID is empty", name, accountId.ResourceGroup, accountId.Name) + } + + d.SetId(*resp.ID) + + if d.HasChange("snapshot_schedule") { + syncFuture, err := syncClient.Delete(ctx, accountId.ResourceGroup, accountId.Name, name, name) + if err != nil { + if !response.WasNotFound(syncFuture.Response()) { + return fmt.Errorf("deleting DataShare %q snapshot schedule (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + } else if err = syncFuture.WaitForCompletionRef(ctx, syncClient.Client); err != nil { + if !response.WasNotFound(syncFuture.Response()) { + return fmt.Errorf("waiting for DataShare %q snapshot schedule (Resource Group %q / accountName %q) to be deleted: %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + } + if snapshotSchedule := expandAzureRmDataShareSnapshotSchedule(d.Get("snapshot_schedule").([]interface{})); snapshotSchedule != nil { + if _, err := syncClient.Create(ctx, accountId.ResourceGroup, accountId.Name, name, name, snapshotSchedule); err != nil { + return fmt.Errorf("creating DataShare %q snapshot schedule (Resource Group %q / accountName %q): %+v", name, accountId.ResourceGroup, accountId.Name, err) + } + } + } + return resourceArmDataShareRead(d, meta) +} + +func resourceArmDataShareRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.SharesClient + accountClient := meta.(*clients.Client).DataShare.AccountClient + syncClient := meta.(*clients.Client).DataShare.SynchronizationClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DataShareID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("retrieving DataShare %q (Resource Group %q / accountName %q): %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + + accountResp, err := accountClient.Get(ctx, id.ResourceGroup, id.AccountName) + if err != nil { + return fmt.Errorf("retrieving DataShare Account %q (Resource Group %q): %+v", id.AccountName, id.ResourceGroup, err) + } + if accountResp.ID == nil || *accountResp.ID == "" { + return fmt.Errorf("reading DataShare Account %q (Resource Group %q): ID is empty", id.AccountName, id.ResourceGroup) + } + + d.Set("name", id.Name) + d.Set("account_id", accountResp.ID) + + if props := resp.ShareProperties; props != nil { + d.Set("share_kind", props.ShareKind) + d.Set("description", props.Description) + d.Set("terms", props.Terms) + } + + syncResp, err := syncClient.Get(ctx, id.ResourceGroup, id.AccountName, id.Name, id.Name) + if err != nil { + // if not found, we set nothing to the block + if !utils.ResponseWasNotFound(syncResp.Response) { + return fmt.Errorf("checking for present of existing DataShare %q snapshot schedule (Resource Group %q / accountName %q): %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + } else { + if schedule := syncResp.Value.(datashare.ScheduledSynchronizationSetting); schedule.ID != nil && *schedule.ID != "" { + if err := d.Set("snapshot_schedule", flattenAzureRmDataShareSnapshotSchedule(&schedule)); err != nil { + return fmt.Errorf("setting `snapshot_schedule`: %+v", err) + } + } + } + + return nil +} + +func resourceArmDataShareDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataShare.SharesClient + syncClient := meta.(*clients.Client).DataShare.SynchronizationClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DataShareID(d.Id()) + if err != nil { + return err + } + + future, err := client.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name) + if err != nil { + return fmt.Errorf("deleting DataShare %q (Resource Group %q / accountName %q): %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("waiting for DataShare %q (Resource Group %q / accountName %q) to be deleted: %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + } + + // force delete sync setting resource whether it exists or not + syncFuture, err := syncClient.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name, id.Name) + if err != nil { + if !response.WasNotFound(syncFuture.Response()) { + return fmt.Errorf("deleting DataShare %q snapshot schedule (Resource Group %q / accountName %q): %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + } else if err = syncFuture.WaitForCompletionRef(ctx, syncClient.Client); err != nil { + if !response.WasNotFound(syncFuture.Response()) { + return fmt.Errorf("waiting for DataShare %q snapshot schedule (Resource Group %q / accountName %q) to be deleted: %+v", id.Name, id.ResourceGroup, id.AccountName, err) + } + } + + return nil +} + +func expandAzureRmDataShareSnapshotSchedule(input []interface{}) *datashare.ScheduledSynchronizationSetting { + if len(input) == 0 { + return nil + } + + snapshotSchedule := input[0].(map[string]interface{}) + + startTime, _ := time.Parse(time.RFC3339, snapshotSchedule["start_time"].(string)) + + return &datashare.ScheduledSynchronizationSetting{ + Kind: datashare.KindBasicSynchronizationSettingKindScheduleBased, + ScheduledSynchronizationSettingProperties: &datashare.ScheduledSynchronizationSettingProperties{ + RecurrenceInterval: datashare.RecurrenceInterval(snapshotSchedule["recurrence"].(string)), + SynchronizationTime: &date.Time{Time: startTime}, + }, + } +} + +func flattenAzureRmDataShareSnapshotSchedule(sync *datashare.ScheduledSynchronizationSetting) []interface{} { + if sync == nil { + return []interface{}{} + } + + var startTime string + if sync.SynchronizationTime != nil && !sync.SynchronizationTime.IsZero() { + startTime = sync.SynchronizationTime.Format(time.RFC3339) + } + + return []interface{}{ + map[string]interface{}{ + "recurrence": string(sync.RecurrenceInterval), + "start_time": startTime, + }, + } +} diff --git a/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go b/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go deleted file mode 100644 index cea24089394a..000000000000 --- a/azurerm/internal/services/datashare/resource_arm_data_share_accounts.go +++ /dev/null @@ -1,190 +0,0 @@ -package datashare - -import ( - "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate" - "log" - "time" - - "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" - "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/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/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmDataShareAccount() *schema.Resource { - return &schema.Resource{ - Create: resourceArmDataShareAccountCreate, - Read: resourceArmDataShareAccountRead, - Update: resourceArmDataShareAccountUpdate, - Delete: resourceArmDataShareAccountDelete, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := parse.DataShareAccountID(id) - return err - }), - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocation(), - - // the api will save and return the tag keys in lowercase, so an extra validation of the key is all in lowercase is added - "tags": { - Type: schema.TypeMap, - Optional: true, - ValidateFunc: validate.DatashareTags, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - } -} -func resourceArmDataShareAccountCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataShare.AccountClient - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Failure in checking for present of existing DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_share_account", *existing.ID) - } - } - - accountProps := datashare.Account{ - Identity: &datashare.Identity{ - Type: "SystemAssigned", - }, - Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), - Name: utils.String(name), - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - } - - future, err := client.Create(ctx, resourceGroup, name, accountProps) - if err != nil { - return fmt.Errorf("Failure in creating DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Failure in waiting on creating future for DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("Cannot read DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.SetId(*resp.ID) - return resourceArmDataShareAccountRead(d, meta) -} - -func resourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataShare.AccountClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := parse.DataShareAccountID(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Failure in retrieving DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - return tags.FlattenAndSet(d, resp.Tags) -} - -func resourceArmDataShareAccountUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataShare.AccountClient - ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if !d.HasChange("tags") { - return nil - } - - id, err := parse.DataShareAccountID(d.Id()) - if err != nil { - return err - } - - props := datashare.AccountUpdateParameters{ - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - } - - _, err = client.Update(ctx, id.ResourceGroup, id.Name, props) - if err != nil { - return fmt.Errorf("Failure in issuing update request for DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - - return resourceArmDataShareAccountRead(d, meta) -} - -func resourceArmDataShareAccountDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataShare.AccountClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := parse.DataShareAccountID(d.Id()) - if err != nil { - return err - } - - future, err := client.Delete(ctx, id.ResourceGroup, id.Name) - if err != nil { - return fmt.Errorf("Failure in deleting DataShare Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Failure in waiting for DataShare Account %q (Resource Group %q) to be deleted: %+v", id.Name, id.ResourceGroup, err) - } - } - return nil -} diff --git a/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go deleted file mode 100644 index 7e01ff0ec375..000000000000 --- a/azurerm/internal/services/datashare/tests/data_source_data_share_accounts_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMDataShareAccount_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_data_share_account", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataShareAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceDataShareAccount_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataShareAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Test"), - ), - }, - }, - }) -} - -func testAccDataSourceDataShareAccount_basic(data acceptance.TestData) string { - config := testAccAzureRMDataShareAccount_complete(data) - return fmt.Sprintf(` -%s -data "azurerm_data_shareaccount" "test" { - name = azurerm_data_share_account.test.name - resource_group_name = azurerm_resource_group.test.name -} -`, config) -} diff --git a/azurerm/internal/services/datashare/tests/data_source_data_share_test.go b/azurerm/internal/services/datashare/tests/data_source_data_share_test.go new file mode 100644 index 000000000000..3a1ee4462746 --- /dev/null +++ b/azurerm/internal/services/datashare/tests/data_source_data_share_test.go @@ -0,0 +1,71 @@ +package tests + +import ( + "fmt" + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMDataShare_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_data_share", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMDataShare_snapshotSchedule(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_data_share", "test") + startTime := time.Now().Add(time.Hour * 7).Format(time.RFC3339) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMDataShare_snapshotSchedule(data, startTime), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccDataSourceDataShare_basic(data acceptance.TestData) string { + config := testAccAzureRMDataShare_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_data_share" "test" { + name = azurerm_data_share.test.name + account_id = azurerm_data_share_account.test.id +} +`, config) +} + +func testAccDataSourceAzureRMDataShare_snapshotSchedule(data acceptance.TestData, startTime string) string { + config := testAccAzureRMDataShare_snapshotSchedule(data, startTime) + return fmt.Sprintf(` +%s + +data "azurerm_data_share" "test" { + name = azurerm_data_share.test.name + account_id = azurerm_data_share_account.test.id +} +`, config) +} diff --git a/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go b/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go deleted file mode 100644 index d9ce0d91e149..000000000000 --- a/azurerm/internal/services/datashare/tests/resource_arm_data_share_accounts_test.go +++ /dev/null @@ -1,203 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func TestAccAzureRMDataShareAccount_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataShareAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDataShareAccount_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataShareAccountExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMDataShareAccount_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataShareAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDataShareAccount_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataShareAccountExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMDataShareAccount_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_data_share_account"), - }, - }, - }) -} - -func TestAccAzureRMDataShareAccount_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_data_share_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataShareAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDataShareAccount_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataShareAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Test"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMDataShareAccount_update(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataShareAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "Stage"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testCheckAzureRMDataShareAccountExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.AccountClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("DataShare Account not found: %s", resourceName) - - } - id, err := parse.DataShareAccountID(rs.Primary.ID) - if err != nil { - return err - } - if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: data_share account %q does not exist", id.Name) - } - return fmt.Errorf("Bad: Get on DataShareAccountClient: %+v", err) - } - return nil - } -} - -func testCheckAzureRMDataShareAccountDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.AccountClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_data_share_account" { - continue - } - id, err := parse.DataShareAccountID(rs.Primary.ID) - if err != nil { - return err - } - if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on data_share.accountClient: %+v", err) - } - } - return nil - } - return nil -} - -func testAccAzureRMDataShareAccount_template(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} -resource "azurerm_resource_group" "test" { - name = "acctest-datashare-%d" - location = "%s" -} -`, data.RandomInteger, data.Locations.Primary) -} - -func testAccAzureRMDataShareAccount_basic(data acceptance.TestData) string { - template := testAccAzureRMDataShareAccount_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_data_share_account" "test" { - name = "acctest-dsa-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name -} -`, template, data.RandomInteger) -} - -func testAccAzureRMDataShareAccount_requiresImport(data acceptance.TestData) string { - config := testAccAzureRMDataShareAccount_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_data_share_account" "import" { - name = azurerm_data_share_account.test.name - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name -} -`, config) -} - -func testAccAzureRMDataShareAccount_complete(data acceptance.TestData) string { - template := testAccAzureRMDataShareAccount_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_data_share_account" "test" { - name = "acctest-dsa-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - tags = { - env = "Test" - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMDataShareAccount_update(data acceptance.TestData) string { - template := testAccAzureRMDataShareAccount_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_data_share_account" "test" { - name = "acctest-dsa-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - tags = { - env = "Stage" - } -} -`, template, data.RandomInteger) -} diff --git a/azurerm/internal/services/datashare/tests/resource_arm_data_share_test.go b/azurerm/internal/services/datashare/tests/resource_arm_data_share_test.go new file mode 100644 index 000000000000..442c564be185 --- /dev/null +++ b/azurerm/internal/services/datashare/tests/resource_arm_data_share_test.go @@ -0,0 +1,303 @@ +package tests + +import ( + "fmt" + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDataShare_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataShare_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMDataShare_requiresImport), + }, + }) +} + +func TestAccAzureRMDataShare_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShare_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataShare_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShare_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShare_update(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataShare_snapshotSchedule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_share", "test") + startTime := time.Now().Add(time.Hour * 7).Format(time.RFC3339) + startTime2 := time.Now().Add(time.Hour * 8).Format(time.RFC3339) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShare_snapshotSchedule(data, startTime), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShare_snapshotScheduleUpdated(data, startTime2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDataShare_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMDataShareExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.SharesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("dataShare not found: %s", resourceName) + } + id, err := parse.DataShareID(rs.Primary.ID) + if err != nil { + return err + } + if resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("bad: data_share share %q does not exist", id.Name) + } + return fmt.Errorf("bad: Get on DataShareClient: %+v", err) + } + return nil + } +} + +func testCheckAzureRMDataShareDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataShare.SharesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_share" { + continue + } + id, err := parse.DataShareID(rs.Primary.ID) + if err != nil { + return err + } + if resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("bad: Get on data_share.shareClient: %+v", err) + } + } + return nil + } + return nil +} +func testAccAzureRMDataShare_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-datashare-%d" + location = "%s" +} + +resource "azurerm_data_share_account" "test" { + name = "acctest-dsa-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + identity { + type = "SystemAssigned" + } + + tags = { + env = "Test" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMDataShare_basic(data acceptance.TestData) string { + template := testAccAzureRMDataShare_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_data_share" "test" { + name = "acctest_ds_%d" + account_id = azurerm_data_share_account.test.id + share_kind = "CopyBased" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDataShare_requiresImport(data acceptance.TestData) string { + config := testAccAzureRMDataShare_basic(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share" "import" { + name = azurerm_data_share.test.name + account_id = azurerm_data_share_account.test.id + share_kind = azurerm_data_share.test.share_kind +} +`, config) +} + +func testAccAzureRMDataShare_complete(data acceptance.TestData) string { + template := testAccAzureRMDataShare_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share" "test" { + name = "acctest_ds_%d" + account_id = azurerm_data_share_account.test.id + share_kind = "CopyBased" + description = "share desc" + terms = "share terms" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDataShare_update(data acceptance.TestData) string { + template := testAccAzureRMDataShare_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_data_share" "test" { + name = "acctest_ds_%d" + account_id = azurerm_data_share_account.test.id + share_kind = "CopyBased" + description = "share desc 2" + terms = "share terms 2" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDataShare_snapshotSchedule(data acceptance.TestData, startTime string) string { + template := testAccAzureRMDataShare_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_data_share" "test" { + name = "acctest_ds_%d" + account_id = azurerm_data_share_account.test.id + share_kind = "CopyBased" + + snapshot_schedule { + recurrence = "Day" + start_time = "%s" + } +} +`, template, data.RandomInteger, startTime) +} + +func testAccAzureRMDataShare_snapshotScheduleUpdated(data acceptance.TestData, startTime string) string { + template := testAccAzureRMDataShare_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_data_share" "test" { + name = "acctest_ds_%d" + account_id = azurerm_data_share_account.test.id + share_kind = "CopyBased" + + snapshot_schedule { + recurrence = "Hour" + start_time = "%s" + } +} +`, template, data.RandomInteger, startTime) +} diff --git a/azurerm/internal/services/datashare/validate/dataShare.go b/azurerm/internal/services/datashare/validate/dataShare.go deleted file mode 100644 index 06b0cb7c2421..000000000000 --- a/azurerm/internal/services/datashare/validate/dataShare.go +++ /dev/null @@ -1,38 +0,0 @@ -package validate - -import ( - "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "strings" -) - -func DatashareTags(i interface{}, k string) (warnings []string, errors []error) { - tagsMap := i.(map[string]interface{}) - - if len(tagsMap) > 50 { - errors = append(errors, fmt.Errorf("a maximum of 50 tags can be applied to each ARM resource")) - } - - for k, v := range tagsMap { - if len(k) > 512 { - errors = append(errors, fmt.Errorf("the maximum length for a tag key is 512 characters: %q is %d characters", k, len(k))) - return warnings, errors - } - - if strings.ToLower(k) != k { - errors = append(errors, fmt.Errorf("a tag key %q expected to be all in lowercase", k)) - return warnings, errors - } - - value, err := tags.TagValueToString(v) - if err != nil { - errors = append(errors, err) - return warnings, errors - } else if len(value) > 256 { - errors = append(errors, fmt.Errorf("the maximum length for a tag value is 256 characters: the value for %q is %d characters", k, len(value))) - return warnings, errors - } - } - - return warnings, errors -} diff --git a/azurerm/internal/services/datashare/validate/data_share.go b/azurerm/internal/services/datashare/validate/data_share.go index 4bd6971dfe22..ea876540697f 100644 --- a/azurerm/internal/services/datashare/validate/data_share.go +++ b/azurerm/internal/services/datashare/validate/data_share.go @@ -1,6 +1,8 @@ package validate import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse" "regexp" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -12,3 +14,23 @@ func DataShareAccountName() schema.SchemaValidateFunc { regexp.MustCompile(`^[^<>%&:\\?/#*$^();,.\|+={}\[\]!~@]{3,90}$`), `Data share account name should have length of 3 - 90, and cannot contain <>%&:\?/#*$^();,.|+={}[]!~@.`, ) } + +func DatashareName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile(`^\w{2,90}$`), `DataShare name can only contain alphanumeric characters and _, and must be between 2 and 90 characters long.`, + ) +} + +func DatashareAccountID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return warnings, errors + } + + if _, err := parse.DataShareAccountID(v); err != nil { + errors = append(errors, fmt.Errorf("can not parse %q as a Datashare account id: %v", k, err)) + } + + return warnings, errors +} diff --git a/azurerm/internal/services/datashare/validate/data_share_test.go b/azurerm/internal/services/datashare/validate/data_share_test.go index 7e3d706bef34..54df8fe2f144 100644 --- a/azurerm/internal/services/datashare/validate/data_share_test.go +++ b/azurerm/internal/services/datashare/validate/data_share_test.go @@ -55,3 +55,42 @@ func TestDataShareAccountName(t *testing.T) { }) } } + +func TestDatashareName(t *testing.T) { + tests := []struct { + name string + input string + valid bool + }{ + { + name: "invalid character", + input: "9()", + valid: false, + }, + { + name: "less character", + input: "a", + valid: false, + }, + { + name: "invalid character2", + input: "adgeFG-98", + valid: false, + }, + { + name: "valid", + input: "dfakF88u7_", + valid: true, + }, + } + var validationFunction = DatashareName() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := validationFunction(tt.input, "") + valid := err == nil + if valid != tt.valid { + t.Errorf("expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) + } + }) + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go b/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go deleted file mode 100644 index b7d296dec725..000000000000 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare/datashareapi/interfaces.go +++ /dev/null @@ -1,164 +0,0 @@ -package datashareapi - -// Copyright (c) Microsoft and contributors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "context" - "github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" - "github.com/Azure/go-autorest/autorest" -) - -// AccountsClientAPI contains the set of methods on the AccountsClient type. -type AccountsClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, account datashare.Account) (result datashare.AccountsCreateFuture, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string) (result datashare.AccountsDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string) (result datashare.Account, err error) - ListByResourceGroup(ctx context.Context, resourceGroupName string, skipToken string) (result datashare.AccountListPage, err error) - ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, skipToken string) (result datashare.AccountListIterator, err error) - ListBySubscription(ctx context.Context, skipToken string) (result datashare.AccountListPage, err error) - ListBySubscriptionComplete(ctx context.Context, skipToken string) (result datashare.AccountListIterator, err error) - Update(ctx context.Context, resourceGroupName string, accountName string, accountUpdateParameters datashare.AccountUpdateParameters) (result datashare.Account, err error) -} - -var _ AccountsClientAPI = (*datashare.AccountsClient)(nil) - -// ConsumerInvitationsClientAPI contains the set of methods on the ConsumerInvitationsClient type. -type ConsumerInvitationsClientAPI interface { - Get(ctx context.Context, location string, invitationID string) (result datashare.ConsumerInvitation, err error) - ListInvitations(ctx context.Context, skipToken string) (result datashare.ConsumerInvitationListPage, err error) - ListInvitationsComplete(ctx context.Context, skipToken string) (result datashare.ConsumerInvitationListIterator, err error) - RejectInvitation(ctx context.Context, location string, invitation datashare.ConsumerInvitation) (result datashare.ConsumerInvitation, err error) -} - -var _ ConsumerInvitationsClientAPI = (*datashare.ConsumerInvitationsClient)(nil) - -// DataSetsClientAPI contains the set of methods on the DataSetsClient type. -type DataSetsClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string, dataSet datashare.BasicDataSet) (result datashare.DataSetModel, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result datashare.DataSetsDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result datashare.DataSetModel, err error) - ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.DataSetListPage, err error) - ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.DataSetListIterator, err error) -} - -var _ DataSetsClientAPI = (*datashare.DataSetsClient)(nil) - -// DataSetMappingsClientAPI contains the set of methods on the DataSetMappingsClient type. -type DataSetMappingsClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string, dataSetMapping datashare.BasicDataSetMapping) (result datashare.DataSetMappingModel, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string) (result autorest.Response, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, dataSetMappingName string) (result datashare.DataSetMappingModel, err error) - ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.DataSetMappingListPage, err error) - ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.DataSetMappingListIterator, err error) -} - -var _ DataSetMappingsClientAPI = (*datashare.DataSetMappingsClient)(nil) - -// InvitationsClientAPI contains the set of methods on the InvitationsClient type. -type InvitationsClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string, invitation datashare.Invitation) (result datashare.Invitation, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string) (result autorest.Response, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, invitationName string) (result datashare.Invitation, err error) - ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.InvitationListPage, err error) - ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.InvitationListIterator, err error) -} - -var _ InvitationsClientAPI = (*datashare.InvitationsClient)(nil) - -// OperationsClientAPI contains the set of methods on the OperationsClient type. -type OperationsClientAPI interface { - List(ctx context.Context) (result datashare.OperationListPage, err error) - ListComplete(ctx context.Context) (result datashare.OperationListIterator, err error) -} - -var _ OperationsClientAPI = (*datashare.OperationsClient)(nil) - -// SharesClientAPI contains the set of methods on the SharesClient type. -type SharesClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, share datashare.Share) (result datashare.Share, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string) (result datashare.SharesDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareName string) (result datashare.Share, err error) - ListByAccount(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareListPage, err error) - ListByAccountComplete(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareListIterator, err error) - ListSynchronizationDetails(ctx context.Context, resourceGroupName string, accountName string, shareName string, shareSynchronization datashare.ShareSynchronization, skipToken string) (result datashare.SynchronizationDetailsListPage, err error) - ListSynchronizationDetailsComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, shareSynchronization datashare.ShareSynchronization, skipToken string) (result datashare.SynchronizationDetailsListIterator, err error) - ListSynchronizations(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ShareSynchronizationListPage, err error) - ListSynchronizationsComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ShareSynchronizationListIterator, err error) -} - -var _ SharesClientAPI = (*datashare.SharesClient)(nil) - -// ProviderShareSubscriptionsClientAPI contains the set of methods on the ProviderShareSubscriptionsClient type. -type ProviderShareSubscriptionsClientAPI interface { - GetByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscription, err error) - ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ProviderShareSubscriptionListPage, err error) - ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.ProviderShareSubscriptionListIterator, err error) - Reinstate(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscription, err error) - Revoke(ctx context.Context, resourceGroupName string, accountName string, shareName string, providerShareSubscriptionID string) (result datashare.ProviderShareSubscriptionsRevokeFuture, err error) -} - -var _ ProviderShareSubscriptionsClientAPI = (*datashare.ProviderShareSubscriptionsClient)(nil) - -// ShareSubscriptionsClientAPI contains the set of methods on the ShareSubscriptionsClient type. -type ShareSubscriptionsClientAPI interface { - CancelSynchronization(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization) (result datashare.ShareSubscriptionsCancelSynchronizationFuture, err error) - Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscription datashare.ShareSubscription) (result datashare.ShareSubscription, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string) (result datashare.ShareSubscriptionsDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string) (result datashare.ShareSubscription, err error) - ListByAccount(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareSubscriptionListPage, err error) - ListByAccountComplete(ctx context.Context, resourceGroupName string, accountName string, skipToken string) (result datashare.ShareSubscriptionListIterator, err error) - ListSourceShareSynchronizationSettings(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.SourceShareSynchronizationSettingListPage, err error) - ListSourceShareSynchronizationSettingsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.SourceShareSynchronizationSettingListIterator, err error) - ListSynchronizationDetails(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization, skipToken string) (result datashare.SynchronizationDetailsListPage, err error) - ListSynchronizationDetailsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, shareSubscriptionSynchronization datashare.ShareSubscriptionSynchronization, skipToken string) (result datashare.SynchronizationDetailsListIterator, err error) - ListSynchronizations(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ShareSubscriptionSynchronizationListPage, err error) - ListSynchronizationsComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ShareSubscriptionSynchronizationListIterator, err error) - SynchronizeMethod(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, synchronize datashare.Synchronize) (result datashare.ShareSubscriptionsSynchronizeMethodFuture, err error) -} - -var _ ShareSubscriptionsClientAPI = (*datashare.ShareSubscriptionsClient)(nil) - -// ConsumerSourceDataSetsClientAPI contains the set of methods on the ConsumerSourceDataSetsClient type. -type ConsumerSourceDataSetsClientAPI interface { - ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ConsumerSourceDataSetListPage, err error) - ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.ConsumerSourceDataSetListIterator, err error) -} - -var _ ConsumerSourceDataSetsClientAPI = (*datashare.ConsumerSourceDataSetsClient)(nil) - -// SynchronizationSettingsClientAPI contains the set of methods on the SynchronizationSettingsClient type. -type SynchronizationSettingsClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string, synchronizationSetting datashare.BasicSynchronizationSetting) (result datashare.SynchronizationSettingModel, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string) (result datashare.SynchronizationSettingsDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, synchronizationSettingName string) (result datashare.SynchronizationSettingModel, err error) - ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.SynchronizationSettingListPage, err error) - ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result datashare.SynchronizationSettingListIterator, err error) -} - -var _ SynchronizationSettingsClientAPI = (*datashare.SynchronizationSettingsClient)(nil) - -// TriggersClientAPI contains the set of methods on the TriggersClient type. -type TriggersClientAPI interface { - Create(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string, trigger datashare.BasicTrigger) (result datashare.TriggersCreateFuture, err error) - Delete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string) (result datashare.TriggersDeleteFuture, err error) - Get(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, triggerName string) (result datashare.TriggerModel, err error) - ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.TriggerListPage, err error) - ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result datashare.TriggerListIterator, err error) -} - -var _ TriggersClientAPI = (*datashare.TriggersClient)(nil) diff --git a/website/azurerm.erb b/website/azurerm.erb index 6c5a4240f2f0..e4b294c33292 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -186,6 +186,10 @@ azurerm_data_lake_store +
  • + azurerm_data_share +
  • +
  • azurerm_data_share_account
  • @@ -1418,6 +1422,9 @@
  • Data Share Resources