-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Data Source: azurerm_eventhub_namespace
#673
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceEventHubNamespace() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEventHubNamespaceRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"sku": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"capacity": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"auto_inflate_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"maximum_throughput_units": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"default_primary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"default_secondary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"default_primary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"default_secondary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).eventHubNamespacesClient | ||
|
||
resourceGroup := d.Get("resource_group_name").(string) | ||
name := d.Get("name").(string) | ||
|
||
resp, err := client.Get(resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("sku", string(resp.Sku.Name)) | ||
d.Set("capacity", resp.Sku.Capacity) | ||
|
||
keys, err := client.ListKeys(resourceGroup, name, eventHubNamespaceDefaultAuthorizationRule) | ||
if err != nil { | ||
log.Printf("[ERROR] Unable to List default keys for EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} else { | ||
d.Set("default_primary_connection_string", keys.PrimaryConnectionString) | ||
d.Set("default_secondary_connection_string", keys.SecondaryConnectionString) | ||
d.Set("default_primary_key", keys.PrimaryKey) | ||
d.Set("default_secondary_key", keys.SecondaryKey) | ||
} | ||
|
||
if props := resp.EHNamespaceProperties; props != nil { | ||
d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled) | ||
d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} |
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,96 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMEventHubNamespace_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_eventhub_namespace.test" | ||
rInt := acctest.RandInt() | ||
location := testLocation() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceEventHubNamespace_basic(rInt, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "sku", "Basic"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMEventHubNamespace_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_eventhub_namespace.test" | ||
rInt := acctest.RandInt() | ||
location := testLocation() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceEventHubNamespace_complete(rInt, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "sku", "Standard"), | ||
resource.TestCheckResourceAttr(dataSourceName, "capacity", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "auto_inflate_enabled", "true"), | ||
resource.TestCheckResourceAttr(dataSourceName, "maximum_throughput_units", "20"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceEventHubNamespace_basic(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_eventhub_namespace" "test" { | ||
name = "acctesteventhubnamespace-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
sku = "Basic" | ||
} | ||
|
||
data "azurerm_eventhub_namespace" "test" { | ||
name = "${azurerm_eventhub_namespace.test.name}" | ||
resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" | ||
} | ||
`, rInt, location, rInt) | ||
} | ||
|
||
func testAccDataSourceEventHubNamespace_complete(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
|
||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_eventhub_namespace" "test" { | ||
name = "acctesteventhubnamespace-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
sku = "Standard" | ||
capacity = "2" | ||
auto_inflate_enabled = true | ||
maximum_throughput_units = 20 | ||
} | ||
|
||
data "azurerm_eventhub_namespace" "test" { | ||
name = "${azurerm_eventhub_namespace.test.name}" | ||
resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" | ||
} | ||
`, rInt, location, rInt) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this worth error-ing out completely instead of just logging? The
ERROR
makes it seem like it's an issue instead of keys just not being there. Might be worth swapping to anINFO
orWARN
tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good shout - I'll update this to a
WARN
👍erroring out completely doesn't make sense since it's valid that a user may have permissions to the EventHub but not the keys (AFAIK)