-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source:
azurerm_eventgrid_domain_topic
(#10050)
Fixes #9340
- Loading branch information
Showing
4 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
azurerm/internal/services/eventgrid/eventgrid_domain_topic_data_source.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,65 @@ | ||
package eventgrid | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"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/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" | ||
) | ||
|
||
func dataSourceEventGridDomainTopic() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEventGridDomainTopicRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"domain_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceEventGridDomainTopicRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).EventGrid.DomainTopicsClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
domainName := d.Get("domain_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, domainName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: EventGrid Domain Topic %s (Resource Group %s) was not found: %+v", name, resourceGroup, err) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on EventGrid Domain Topic '%s': %+v", name, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("domain_name", domainName) | ||
|
||
return nil | ||
} |
39 changes: 39 additions & 0 deletions
39
azurerm/internal/services/eventgrid/eventgrid_domain_topic_data_source_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,39 @@ | ||
package eventgrid_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" | ||
) | ||
|
||
type EventGridDomainTopicDataSource struct { | ||
} | ||
|
||
func TestAccEventGridDomainTopicDataSource_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_eventgrid_domain_topic", "test") | ||
r := EventGridDomainTopicDataSource{} | ||
|
||
data.DataSourceTest(t, []resource.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: resource.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("domain_name").Exists(), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (EventGridDomainTopicDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_eventgrid_domain_topic" "test" { | ||
name = azurerm_eventgrid_domain_topic.test.name | ||
domain_name = azurerm_eventgrid_domain_topic.test.domain_name | ||
resource_group_name = azurerm_resource_group.test.name | ||
} | ||
`, EventGridDomainTopicResource{}.basic(data)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
subcategory: "Messaging" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_eventgrid_domain_topic" | ||
description: |- | ||
Gets information about an existing EventGrid Domain Topic | ||
--- | ||
|
||
# Data Source: azurerm_eventgrid_domain_topic | ||
|
||
Use this data source to access information about an existing EventGrid Domain Topic | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_eventgrid_domain_topic" "example" { | ||
name = "my-eventgrid-domain-topic" | ||
resource_group_name = "example-resources" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - The name of the EventGrid Domain Topic resource. | ||
|
||
* `domain_name` - The name of the EventGrid Domain Topic domain. | ||
|
||
* `resource_group_name` - The name of the resource group in which the EventGrid Domain Topic exists. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The EventGrid Domain Topic ID. | ||
|
||
* `domain_name` - The EventGrid Domain Topic Domain name. | ||
|
||
## Timeouts | ||
|
||
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 EventGrid Domain Topic. |