Skip to content

Commit 862c89a

Browse files
New Data Source: azurerm_dev_center_dev_box_definition (#29790)
[FEATURE] * **New Data Source**: `azurerm_dev_center_dev_box_definition`
1 parent 1198d30 commit 862c89a

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package devcenter
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"time"
10+
11+
"github.com/hashicorp/go-azure-helpers/lang/pointer"
12+
"github.com/hashicorp/go-azure-helpers/lang/response"
13+
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
14+
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
15+
"github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2025-02-01/devboxdefinitions"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
18+
"github.com/hashicorp/terraform-provider-azurerm/internal/services/devcenter/validate"
19+
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
20+
)
21+
22+
var _ sdk.DataSource = DevCenterDevBoxDefinitionDataSource{}
23+
24+
type DevCenterDevBoxDefinitionDataSource struct{}
25+
26+
type DevCenterDevBoxDefinitionDataSourceModel struct {
27+
Name string `tfschema:"name"`
28+
Location string `tfschema:"location"`
29+
DevCenterId string `tfschema:"dev_center_id"`
30+
ImageReferenceId string `tfschema:"image_reference_id"`
31+
SkuName string `tfschema:"sku_name"`
32+
Tags map[string]string `tfschema:"tags"`
33+
}
34+
35+
func (DevCenterDevBoxDefinitionDataSource) Arguments() map[string]*pluginsdk.Schema {
36+
return map[string]*pluginsdk.Schema{
37+
"name": {
38+
Type: pluginsdk.TypeString,
39+
Required: true,
40+
ValidateFunc: validate.DevCenterDevBoxDefinitionName,
41+
},
42+
43+
"dev_center_id": commonschema.ResourceIDReferenceRequired(&devboxdefinitions.DevCenterId{}),
44+
}
45+
}
46+
47+
func (DevCenterDevBoxDefinitionDataSource) Attributes() map[string]*pluginsdk.Schema {
48+
return map[string]*pluginsdk.Schema{
49+
"image_reference_id": {
50+
Type: schema.TypeString,
51+
Computed: true,
52+
},
53+
54+
"location": commonschema.LocationComputed(),
55+
56+
"sku_name": {
57+
Type: pluginsdk.TypeString,
58+
Computed: true,
59+
},
60+
61+
"tags": commonschema.TagsDataSource(),
62+
}
63+
}
64+
65+
func (DevCenterDevBoxDefinitionDataSource) ModelObject() interface{} {
66+
return &DevCenterDevBoxDefinitionDataSourceModel{}
67+
}
68+
69+
func (DevCenterDevBoxDefinitionDataSource) ResourceType() string {
70+
return "azurerm_dev_center_dev_box_definition"
71+
}
72+
73+
func (r DevCenterDevBoxDefinitionDataSource) Read() sdk.ResourceFunc {
74+
return sdk.ResourceFunc{
75+
Timeout: 5 * time.Minute,
76+
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
77+
client := metadata.Client.DevCenter.V20250201.DevBoxDefinitions
78+
subscriptionId := metadata.Client.Account.SubscriptionId
79+
80+
var state DevCenterDevBoxDefinitionDataSourceModel
81+
if err := metadata.Decode(&state); err != nil {
82+
return fmt.Errorf("decoding: %+v", err)
83+
}
84+
85+
devCenterId, err := devboxdefinitions.ParseDevCenterID(state.DevCenterId)
86+
if err != nil {
87+
return err
88+
}
89+
90+
id := devboxdefinitions.NewDevCenterDevBoxDefinitionID(subscriptionId, devCenterId.ResourceGroupName, devCenterId.DevCenterName, state.Name)
91+
92+
resp, err := client.Get(ctx, id)
93+
if err != nil {
94+
if response.WasNotFound(resp.HttpResponse) {
95+
return fmt.Errorf("%s was not found", id)
96+
}
97+
98+
return fmt.Errorf("retrieving %s: %+v", id, err)
99+
}
100+
101+
metadata.SetID(id)
102+
103+
state.Name = id.DevBoxDefinitionName
104+
state.DevCenterId = devboxdefinitions.NewDevCenterID(id.SubscriptionId, id.ResourceGroupName, id.DevCenterName).ID()
105+
106+
if model := resp.Model; model != nil {
107+
state.Location = location.Normalize(model.Location)
108+
state.Tags = pointer.From(model.Tags)
109+
110+
if props := model.Properties; props != nil {
111+
if v := props.ImageReference; v != nil {
112+
state.ImageReferenceId = pointer.From(v.Id)
113+
}
114+
115+
if v := props.Sku; v != nil {
116+
state.SkuName = v.Name
117+
}
118+
}
119+
}
120+
121+
return metadata.Encode(&state)
122+
},
123+
}
124+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package devcenter_test
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
11+
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
12+
)
13+
14+
type DevCenterDevBoxDefinitionDataSource struct{}
15+
16+
func TestAccDevCenterDevBoxDefinitionDataSource_basic(t *testing.T) {
17+
data := acceptance.BuildTestData(t, "data.azurerm_dev_center_dev_box_definition", "test")
18+
r := DevCenterDevBoxDefinitionDataSource{}
19+
20+
data.DataSourceTest(t, []acceptance.TestStep{
21+
{
22+
Config: r.basic(data),
23+
Check: acceptance.ComposeTestCheckFunc(
24+
check.That(data.ResourceName).Key("name").Exists(),
25+
check.That(data.ResourceName).Key("dev_center_id").Exists(),
26+
check.That(data.ResourceName).Key("location").Exists(),
27+
check.That(data.ResourceName).Key("image_reference_id").Exists(),
28+
check.That(data.ResourceName).Key("sku_name").Exists(),
29+
),
30+
},
31+
})
32+
}
33+
34+
func (d DevCenterDevBoxDefinitionDataSource) basic(data acceptance.TestData) string {
35+
return fmt.Sprintf(`
36+
%s
37+
38+
data "azurerm_dev_center_dev_box_definition" "test" {
39+
name = azurerm_dev_center_dev_box_definition.test.name
40+
dev_center_id = azurerm_dev_center_dev_box_definition.test.dev_center_id
41+
}
42+
`, DevCenterDevBoxDefinitionTestResource{}.basic(data))
43+
}

internal/services/devcenter/registration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (r Registration) DataSources() []sdk.DataSource {
2929
return []sdk.DataSource{
3030
DevCenterCatalogDataSource{},
3131
DevCenterDataSource{},
32+
DevCenterDevBoxDefinitionDataSource{},
3233
DevCenterGalleryDataSource{},
3334
DevCenterNetworkConnectionDataSource{},
3435
DevCenterProjectDataSource{},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
subcategory: "Dev Center"
3+
layout: "azurerm"
4+
page_title: "Azure Resource Manager: Data Source: azurerm_dev_center_dev_box_definition"
5+
description: |-
6+
Gets information about an existing Dev Center Dev Box Definition.
7+
---
8+
9+
# Data Source: azurerm_dev_center_dev_box_definition
10+
11+
Use this data source to access information about an existing Dev Center Dev Box Definition.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "azurerm_dev_center_dev_box_definition" "example" {
17+
name = azurerm_dev_center_dev_box_definition.example.name
18+
dev_center_id = azurerm_dev_center_dev_box_definition.example.dev_center_id
19+
}
20+
21+
output "id" {
22+
value = data.azurerm_dev_center_dev_box_definition.example.id
23+
}
24+
```
25+
26+
## Arguments Reference
27+
28+
The following arguments are supported:
29+
30+
* `name` - (Required) The name of this Dev Center Dev Box Definition.
31+
32+
* `dev_center_id` - (Required) The ID of the associated Dev Center.
33+
34+
## Attributes Reference
35+
36+
In addition to the Arguments listed above - the following Attributes are exported:
37+
38+
* `id` - The ID of the Dev Center Dev Box Definition.
39+
40+
* `image_reference_id` - The ID of the image for the Dev Center Dev Box Definition.
41+
42+
* `location` - The Azure Region where the Dev Center Dev Box Definition exists.
43+
44+
* `sku_name` - The name of the SKU for the Dev Center Dev Box Definition.
45+
46+
* `tags` - A mapping of tags assigned to the Dev Center Dev Box Definition.
47+
48+
## Timeouts
49+
50+
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
51+
52+
* `read` - (Defaults to 5 minutes) Used when retrieving the Dev Center Dev Box Definition.

0 commit comments

Comments
 (0)