Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
4,653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
azurerm/internal/services/eventhub/resource_arm_eventhub_cluster.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package eventhub | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" | ||
"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/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
"log" | ||
"time" | ||
) | ||
|
||
func resourceArmEventHubCluster() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmEventHubClusterCreate, | ||
Read: resourceArmEventHubClusterRead, | ||
Delete: resourceArmEventHubClusterDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
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), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateEventHubName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"location": azure.SchemaLocation(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmEventHubClusterCreate(d *schema.ResourceData, meta interface{}) error { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
client := meta.(*clients.Client).Eventhub.ClusterClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
log.Printf("[INFO] preparing arguments for Azure ARM EventHub Cluster creation.") | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
cluster := eventhub.Cluster{ | ||
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), | ||
// Tags: nil, | ||
} | ||
|
||
future, err := client.Patch(ctx, resourceGroup, name, cluster) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("creating eventhub cluster: %+v", err) | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if read.ID == nil { | ||
return fmt.Errorf("cannot read EventHub Cluster %s (resource group %s) ID", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmEventHubClusterRead(d, meta) | ||
} | ||
|
||
func resourceArmEventHubClusterRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.ClusterClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["clusters"] | ||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("making Read request on Azure EventHub Cluster %q (resource group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmEventHubClusterDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.ClusterClient | ||
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["clusters"] | ||
future, err := client.Delete(ctx, resourceGroup, name) | ||
|
||
if err != nil { | ||
if response.WasNotFound(future.Response()) { | ||
return nil | ||
} | ||
return fmt.Errorf("issuing delete request for EventHub Cluster %q (resource group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
if response.WasNotFound(future.Response()) { | ||
return nil | ||
} | ||
return fmt.Errorf("error deleting EventHub Cluster %s (resource group %s): %+v", name, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} |
106 changes: 106 additions & 0 deletions
106
azurerm/internal/services/eventhub/tests/resource_arm_eventhub_cluster_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"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" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestAccAzureRMEventHubCluster_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_eventhub_cluster", "test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.PreCheck(t) }, | ||
Providers: acceptance.SupportedProviders, | ||
CheckDestroy: testCheckAzureRMEventHubClusterDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAzureRMEventHubCluster_basic(data), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMEventHubClusterExists(data.ResourceName), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckAzureRMEventHubClusterDestroy(s *terraform.State) error { | ||
conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.ClusterClient | ||
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "azurerm_eventhub_cluster" { | ||
continue | ||
} | ||
|
||
name := rs.Primary.Attributes["name"] | ||
resourceGroup := rs.Primary.Attributes["resource_group_name"] | ||
|
||
resp, err := conn.Get(ctx, resourceGroup, name) | ||
|
||
if err != nil { | ||
return nil | ||
} | ||
|
||
if resp.StatusCode != http.StatusNotFound { | ||
return fmt.Errorf("EventHub Cluster still exists:\n%#v", resp.ClusterProperties) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testCheckAzureRMEventHubClusterExists(resourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.ClusterClient | ||
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext | ||
|
||
// Ensure we have enough information in state to look up in API | ||
rs, ok := s.RootModule().Resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", resourceName) | ||
} | ||
|
||
name := rs.Primary.Attributes["name"] | ||
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] | ||
if !hasResourceGroup { | ||
return fmt.Errorf("Bad: no resource group found in state for Event Hub Cluster: %s", name) | ||
} | ||
|
||
resp, err := conn.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Bad: Get on clustersClient: %+v", err) | ||
} | ||
|
||
if resp.StatusCode == http.StatusNotFound { | ||
return fmt.Errorf("Bad: Event Hub Cluster %q (resource group: %q) does not exist", name, resourceGroup) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccAzureRMEventHubCluster_basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-eventhub-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_eventhub_cluster" "test" { | ||
name = "acctesteventhubcluster-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) | ||
} |
52 changes: 52 additions & 0 deletions
52
...ure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub/client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
It seems Azure/azure-sdk-for-go#8533 has been addressed. Any chance you could pick this work up please? :)