Skip to content
Merged
Prev Previous commit
Next Next commit
export url
  • Loading branch information
magodo committed Mar 10, 2025
commit cdd66d358ff2d463463dcc3624c34cbb5803d919
22 changes: 22 additions & 0 deletions internal/services/storage/storage_queue_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func dataSourceStorageQueue() *pluginsdk.Resource {
},

"metadata": MetaDataComputedSchema(),

"url": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}

Expand Down Expand Up @@ -126,6 +131,7 @@ func dataSourceStorageQueueRead(d *pluginsdk.ResourceData, meta interface{}) err

resourceManagerId := parse.NewStorageQueueResourceManagerID(account.StorageAccountId.SubscriptionId, account.StorageAccountId.ResourceGroupName, account.StorageAccountId.StorageAccountName, "default", queueName)
d.Set("resource_manager_id", resourceManagerId.ID())
d.Set("url", id.ID())

return nil
}
Expand Down Expand Up @@ -155,6 +161,22 @@ func dataSourceStorageQueueRead(d *pluginsdk.ResourceData, meta interface{}) err
}
}

account, err := meta.(*clients.Client).Storage.GetAccount(ctx, commonids.NewStorageAccountID(id.SubscriptionId, id.ResourceGroupName, id.StorageAccountName))
if err != nil {
return fmt.Errorf("retrieving Account for Queue %q: %v", id, err)
}
// Determine the queue endpoint, so we can build a data plane ID
endpoint, err := account.DataPlaneEndpoint(client.EndpointTypeQueue)
if err != nil {
return fmt.Errorf("determining Queue endpoint: %v", err)
}
// Parse the queue endpoint as a data plane account ID
accountDpId, err := accounts.ParseAccountID(*endpoint, meta.(*clients.Client).Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("parsing Account ID: %v", err)
}
d.Set("url", queues.NewQueueID(*accountDpId, id.QueueName).ID())

if !features.FivePointOh() {
d.Set("resource_manager_id", id.ID())
}
Expand Down
2 changes: 2 additions & 0 deletions internal/services/storage/storage_queue_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestAccDataSourceStorageQueue_basic(t *testing.T) {
check.That(data.ResourceName).Key("metadata.%").HasValue("2"),
check.That(data.ResourceName).Key("metadata.k1").HasValue("v1"),
check.That(data.ResourceName).Key("metadata.k2").HasValue("v2"),
check.That(data.ResourceName).Key("url").HasValue(fmt.Sprintf("https://acctestsadsc%[1]s.queue.core.windows.net/queuedstest-%[1]s", data.RandomString)),
),
},
})
Expand All @@ -43,6 +44,7 @@ func TestAccDataSourceStorageQueue_basicDeprecated(t *testing.T) {
check.That(data.ResourceName).Key("metadata.%").HasValue("2"),
check.That(data.ResourceName).Key("metadata.k1").HasValue("v1"),
check.That(data.ResourceName).Key("metadata.k2").HasValue("v2"),
check.That(data.ResourceName).Key("url").HasValue(fmt.Sprintf("https://acctestsadsc%[1]s.queue.core.windows.net/queuedstest-%[1]s", data.RandomString)),
),
},
})
Expand Down
22 changes: 22 additions & 0 deletions internal/services/storage/storage_queue_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func resourceStorageQueue() *pluginsdk.Resource {
},

"metadata": MetaDataSchema(),

"url": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}

Expand Down Expand Up @@ -314,6 +319,7 @@ func resourceStorageQueueRead(d *pluginsdk.ResourceData, meta interface{}) error

resourceManagerId := parse.NewStorageQueueResourceManagerID(account.StorageAccountId.SubscriptionId, account.StorageAccountId.ResourceGroupName, id.AccountId.AccountName, "default", id.QueueName)
d.Set("resource_manager_id", resourceManagerId.ID())
d.Set("url", id.ID())

return nil
}
Expand Down Expand Up @@ -346,6 +352,22 @@ func resourceStorageQueueRead(d *pluginsdk.ResourceData, meta interface{}) error
}
}

account, err := meta.(*clients.Client).Storage.GetAccount(ctx, commonids.NewStorageAccountID(id.SubscriptionId, id.ResourceGroupName, id.StorageAccountName))
if err != nil {
return fmt.Errorf("retrieving Account for Queue %q: %v", id, err)
}
// Determine the queue endpoint, so we can build a data plane ID
endpoint, err := account.DataPlaneEndpoint(client.EndpointTypeQueue)
if err != nil {
return fmt.Errorf("determining Queue endpoint: %v", err)
}
// Parse the queue endpoint as a data plane account ID
accountDpId, err := accounts.ParseAccountID(*endpoint, meta.(*clients.Client).Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("parsing Account ID: %v", err)
}
d.Set("url", queues.NewQueueID(*accountDpId, id.QueueName).ID())

if !features.FivePointOh() {
d.Set("resource_manager_id", id.ID())
}
Expand Down
2 changes: 2 additions & 0 deletions internal/services/storage/storage_queue_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccStorageQueue_basic(t *testing.T) {
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("url").HasValue(fmt.Sprintf("https://acctestacc%s.queue.core.windows.net/mysamplequeue-%d", data.RandomString, data.RandomInteger)),
),
},
data.ImportStep(),
Expand All @@ -50,6 +51,7 @@ func TestAccStorageQueue_basicDeprecated(t *testing.T) {
Config: r.basicDeprecated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("url").HasValue(fmt.Sprintf("https://acctestacc%s.queue.core.windows.net/mysamplequeue-%d", data.RandomString, data.RandomInteger)),
),
},
data.ImportStep(),
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/storage_queue.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The following arguments are supported:

* `resource_manager_id` - The Resource Manager ID of this Storage Queue.

* `url` - The data plane URL of the Storage Queue in the format of `<storage queue endpoint>/<queue name>`. E.g. `https://example.queue.core.windows.net/queue1`.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/storage_queue.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `resource_manager_id` - The Resource Manager ID of this Storage Queue.

* `url` - The data plane URL of the Storage Queue in the format of `<storage queue endpoint>/<queue name>`. E.g. `https://example.queue.core.windows.net/queue1`.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
Expand Down
Loading