func resourceArmStorageTableCreate(d *schema.ResourceData, meta interface{}) error { armClient := meta.(*ArmClient) resourceGroupName := d.Get("resource_group_name").(string) storageAccountName := d.Get("storage_account_name").(string) tableClient, accountExists, err := armClient.getTableServiceClientForStorageAccount(resourceGroupName, storageAccountName) if err != nil { return err } if !accountExists { return fmt.Errorf("Storage Account %q Not Found", storageAccountName) } name := d.Get("name").(string) table := storage.AzureTable(name) log.Printf("[INFO] Creating table %q in storage account %q.", name, storageAccountName) err = tableClient.CreateTable(table) if err != nil { return fmt.Errorf("Error creating table %q in storage account %q: %s", name, storageAccountName, err) } d.SetId(name) return resourceArmStorageTableRead(d, meta) }
func testAccARMStorageTableDisappears(name string, t *storage.AzureTable) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { return fmt.Errorf("Not found: %s", name) } armClient := testAccProvider.Meta().(*ArmClient) storageAccountName := rs.Primary.Attributes["storage_account_name"] resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] if !hasResourceGroup { return fmt.Errorf("Bad: no resource group found in state for storage table: %s", string(*t)) } tableClient, accountExists, err := armClient.getTableServiceClientForStorageAccount(resourceGroup, storageAccountName) if err != nil { return err } if !accountExists { log.Printf("[INFO]Storage Account %q doesn't exist so the table won't exist", storageAccountName) return nil } table := storage.AzureTable(string(*t)) err = tableClient.DeleteTable(table) if err != nil { return err } return nil } }
func resourceArmStorageTableDelete(d *schema.ResourceData, meta interface{}) error { armClient := meta.(*ArmClient) resourceGroupName := d.Get("resource_group_name").(string) storageAccountName := d.Get("storage_account_name").(string) tableClient, accountExists, err := armClient.getTableServiceClientForStorageAccount(resourceGroupName, storageAccountName) if err != nil { return err } if !accountExists { log.Printf("[INFO]Storage Account %q doesn't exist so the table won't exist", storageAccountName) return nil } name := d.Get("name").(string) table := storage.AzureTable(name) log.Printf("[INFO] Deleting storage table %q in account %q", name, storageAccountName) if err := tableClient.DeleteTable(table); err != nil { return fmt.Errorf("Error deleting storage table %q from storage account %q: %s", name, storageAccountName, err) } d.SetId("") return nil }