-
Notifications
You must be signed in to change notification settings - Fork 5k
Add azurerm_playwright_workspace resource and data source
#31954
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
Draft
v-yhyeo0202
wants to merge
16
commits into
hashicorp:main
Choose a base branch
from
v-yhyeo0202:add-playwright-workspace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9e19813
Add `azurerm_playwright_workspace` resource and data source
v-yhyeo0202 3ec32f0
Add Load Testing Service API version 2025-09-01
v-yhyeo0202 eb51941
`azurerm_playwright_workspace` - minor revision
v-yhyeo0202 cab7d33
`azurerm_playwright_workspace` - generate resource identity acctest
v-yhyeo0202 2d7feb2
Add changes due to `make generate`
v-yhyeo0202 ba55bbf
Load testing service - set location rotation to `false`
v-yhyeo0202 14efeb4
`azurerm_playwright_workspace` - fix according to AI
v-yhyeo0202 61ca288
`azurerm_playwright_workspace` - fix according to AI
v-yhyeo0202 20217ed
`azurerm_playwright_workspace` - fix location rate limit issue
v-yhyeo0202 da00686
`azurerm_playwright_workspace` - fix `TestAccPlaywrightWorkspaceDataS…
v-yhyeo0202 bce18e0
`azurerm_resource_group` - fix typo
v-yhyeo0202 544c9dc
`azurerm_security_center_storage_defender` - revise according to revi…
v-yhyeo0202 31bcfe3
`azurerm_playwright_workspace` - revise according to review comment
v-yhyeo0202 76ed225
`azurerm_playwright_workspace` - revise according to review comment
v-yhyeo0202 43a8f1f
`azurerm_playwright_workspace` - fix according to review comment
v-yhyeo0202 f88d271
Merge branch 'main' into add-playwright-workspace
v-yhyeo0202 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,12 +7,14 @@ import ( | |
| "fmt" | ||
|
|
||
| loadtestserviceV20221201 "github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2022-12-01" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2025-09-01/playwrightworkspaces" | ||
| "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
| ) | ||
|
|
||
| type AutoClient struct { | ||
| V20221201 loadtestserviceV20221201.Client | ||
| V20221201 loadtestserviceV20221201.Client | ||
| PlaywrightWorkspacesClient *playwrightworkspaces.PlaywrightWorkspacesClient | ||
| } | ||
|
|
||
| func NewClient(o *common.ClientOptions) (*AutoClient, error) { | ||
|
|
@@ -23,7 +25,14 @@ func NewClient(o *common.ClientOptions) (*AutoClient, error) { | |
| return nil, fmt.Errorf("building client for loadtestservice V20221201: %+v", err) | ||
| } | ||
|
|
||
| playwrightWorkspacesClient, err := playwrightworkspaces.NewPlaywrightWorkspacesClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("building PlaywrightWorkspaces Client: %+v", err) | ||
| } | ||
| o.Configure(playwrightWorkspacesClient.Client, o.Authorizers.ResourceManager) | ||
|
|
||
| return &AutoClient{ | ||
| V20221201: *v20221201Client, | ||
| V20221201: *v20221201Client, | ||
| PlaywrightWorkspacesClient: playwrightWorkspacesClient, | ||
|
Comment on lines
34
to
+36
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disagree as the current format is widely applied |
||
| }, nil | ||
| } | ||
118 changes: 118 additions & 0 deletions
118
internal/services/loadtestservice/playwright_workspace_data_source.go
This file contains hidden or 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,118 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package loadtestservice | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "regexp" | ||
| "time" | ||
|
|
||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
| "github.com/hashicorp/go-azure-helpers/lang/response" | ||
| "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
| "github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2025-09-01/playwrightworkspaces" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
| ) | ||
|
|
||
| type PlaywrightWorkspaceDataSource struct{} | ||
|
|
||
| var _ sdk.DataSource = PlaywrightWorkspaceDataSource{} | ||
|
|
||
| type PlaywrightWorkspaceDataSourceModel struct { | ||
| Name string `tfschema:"name"` | ||
| ResourceGroupName string `tfschema:"resource_group_name"` | ||
| Location string `tfschema:"location"` | ||
| DataplaneUri string `tfschema:"dataplane_uri"` | ||
| WorkspaceId string `tfschema:"workspace_id"` | ||
| Tags map[string]string `tfschema:"tags"` | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) Arguments() map[string]*pluginsdk.Schema { | ||
| return map[string]*pluginsdk.Schema{ | ||
| "name": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ValidateFunc: validation.StringMatch( | ||
| regexp.MustCompile(`^[a-zA-Z0-9-]{3,24}$`), | ||
| "length of `name` must be between 3 and 24 characters (inclusive) and contain only numbers, letters, and hyphens (-)"), | ||
| }, | ||
|
|
||
| "resource_group_name": commonschema.ResourceGroupNameForDataSource(), | ||
| } | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
| return map[string]*pluginsdk.Schema{ | ||
| "location": commonschema.LocationComputed(), | ||
|
|
||
| "dataplane_uri": { | ||
| Type: pluginsdk.TypeString, | ||
| Computed: true, | ||
| }, | ||
|
|
||
| "workspace_id": { | ||
| Type: pluginsdk.TypeString, | ||
| Computed: true, | ||
| }, | ||
|
|
||
| "tags": commonschema.TagsDataSource(), | ||
| } | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) ModelObject() interface{} { | ||
| return &PlaywrightWorkspaceDataSourceModel{} | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) ResourceType() string { | ||
| return "azurerm_playwright_workspace" | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) Read() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 5 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.LoadTestService.PlaywrightWorkspacesClient | ||
| subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
|
||
| var state PlaywrightWorkspaceDataSourceModel | ||
| if err := metadata.Decode(&state); err != nil { | ||
| return fmt.Errorf("decoding: %+v", err) | ||
| } | ||
|
|
||
| id := playwrightworkspaces.NewPlaywrightWorkspaceID(subscriptionId, state.ResourceGroupName, state.Name) | ||
| resp, err := client.Get(ctx, id) | ||
| if err != nil { | ||
| if response.WasNotFound(resp.HttpResponse) { | ||
| return fmt.Errorf("%s was not found", id) | ||
| } | ||
|
|
||
| return fmt.Errorf("retrieving %s: %+v", id, err) | ||
| } | ||
|
|
||
| metadata.SetID(id) | ||
|
|
||
| if model := resp.Model; model != nil { | ||
| state.Location = location.NormalizeNilable(&model.Location) | ||
|
|
||
| if properties := model.Properties; properties != nil { | ||
| if dataplaneUri := properties.DataplaneUri; dataplaneUri != nil { | ||
| state.DataplaneUri = pointer.From(dataplaneUri) | ||
| } | ||
|
|
||
| if workspaceId := properties.WorkspaceId; workspaceId != nil { | ||
| state.WorkspaceId = pointer.From(workspaceId) | ||
| } | ||
| } | ||
|
|
||
| state.Tags = pointer.From(model.Tags) | ||
| } | ||
|
|
||
| return metadata.Encode(&state) | ||
| }, | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
internal/services/loadtestservice/playwright_workspace_data_source_test.go
This file contains hidden or 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,63 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package loadtestservice_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
| ) | ||
|
|
||
| type PlaywrightWorkspaceDataSource struct{} | ||
|
|
||
| func TestAccPlaywrightWorkspaceDataSource_basic(t *testing.T) { | ||
| data := acceptance.BuildTestData(t, "data.azurerm_playwright_workspace", "test") | ||
| r := PlaywrightWorkspaceDataSource{} | ||
|
|
||
| data.DataSourceTest(t, []acceptance.TestStep{ | ||
| { | ||
| Config: r.basic(data), | ||
| Check: acceptance.ComposeTestCheckFunc( | ||
| check.That(data.ResourceName).Key("location").HasValue(location.Normalize(data.Locations.Secondary)), | ||
| check.That(data.ResourceName).Key("dataplane_uri").Exists(), | ||
| check.That(data.ResourceName).Key("workspace_id").Exists(), | ||
| check.That(data.ResourceName).Key("tags.%").HasValue("2"), | ||
| check.That(data.ResourceName).Key("tags.Environment").HasValue("Sandbox"), | ||
| check.That(data.ResourceName).Key("tags.Label").HasValue("Test"), | ||
| ), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func (PlaywrightWorkspaceDataSource) basic(data acceptance.TestData) string { | ||
| return fmt.Sprintf(` | ||
| provider "azurerm" { | ||
| features {} | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "test" { | ||
| name = "acctest-rg-pww-%d" | ||
| location = "%s" | ||
| } | ||
|
|
||
| resource "azurerm_playwright_workspace" "test" { | ||
| name = "acctest-pww-%d" | ||
| resource_group_name = azurerm_resource_group.test.name | ||
| location = azurerm_resource_group.test.location | ||
|
|
||
| tags = { | ||
| Environment = "Sandbox" | ||
| Label = "Test" | ||
| } | ||
| } | ||
|
|
||
| data "azurerm_playwright_workspace" "test" { | ||
| name = azurerm_playwright_workspace.test.name | ||
| resource_group_name = azurerm_playwright_workspace.test.resource_group_name | ||
| } | ||
| `, data.RandomInteger, data.Locations.Secondary, data.RandomIntOfLength(8)) | ||
| } |
Oops, something went wrong.
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.
Disagree as the current format is widely applied