Skip to content

Commit

Permalink
New data source: azurerm_eventgrid_domain_topic (#10050)
Browse files Browse the repository at this point in the history
Fixes #9340
  • Loading branch information
favoretti authored Jan 5, 2021
1 parent 11c7a32 commit ea5ed53
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 1 deletion.
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
}
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))
}
3 changes: 2 additions & 1 deletion azurerm/internal/services/eventgrid/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func (r Registration) WebsiteCategories() []string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_eventgrid_topic": dataSourceEventGridTopic(),
"azurerm_eventgrid_topic": dataSourceEventGridTopic(),
"azurerm_eventgrid_domain_topic": dataSourceEventGridDomainTopic(),
}
}

Expand Down
45 changes: 45 additions & 0 deletions website/docs/d/eventgrid_domain_topic.html.markdown
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.

0 comments on commit ea5ed53

Please sign in to comment.