Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
aab6731
boilerplate service code
mryanlo Dec 25, 2024
4c3f492
boilerplate service package
mryanlo Dec 30, 2024
d68570d
AEP resource
mryanlo Dec 30, 2024
9608e73
fix build errors and lints
mryanlo Dec 30, 2024
a8d1a18
lint
mryanlo Dec 30, 2024
9397281
cleanup and lint for AEP
mryanlo Dec 30, 2024
96b2367
update aep + asset resource
mryanlo Dec 31, 2024
4c3891e
vendor dependencies
mryanlo Dec 31, 2024
8c9fdd8
update codeowners to add device registry required reviewers for devic…
mryanlo Dec 31, 2024
7a1b1a5
fix build errors in aep and asset resource types
mryanlo Dec 31, 2024
287a79c
remove untyped service
mryanlo Dec 31, 2024
32aced7
run `go generate ./internal/provider`
mryanlo Dec 31, 2024
2033c9a
documentation for asset and AEP resources, removing asset and AEP rea…
mryanlo Jan 28, 2025
6d24814
fix aep resource bugs
mryanlo Jan 31, 2025
3ef00f4
simplify update logic for aep auth methods
mryanlo Feb 3, 2025
54394e5
fix bugs in asset resource
mryanlo Feb 3, 2025
bdb3547
documentation example updates
mryanlo Feb 3, 2025
5435de0
remove attributes fields from documentation
mryanlo Feb 4, 2025
e3ef30f
rough draft of tests
mryanlo Feb 7, 2025
36600f5
Merge branch 'main' of https://github.com/mryanlo/terraform-provider-…
mryanlo Feb 7, 2025
09a5eb4
add kind.yaml
mryanlo Feb 7, 2025
547600d
snake case aep names to fix validation errors
mryanlo Feb 8, 2025
62e4291
lint
mryanlo Feb 8, 2025
4ec9666
delete aio cluster setup scripts, make asset tests, change aep tests …
mryanlo Feb 19, 2025
505965b
add comment
mryanlo Feb 19, 2025
f2669aa
add back documentation uri update asset
mryanlo Feb 19, 2025
a38f5c7
fix asset test
mryanlo Feb 19, 2025
e877e4f
Merge branch 'main' of https://github.com/mryanlo/terraform-provider-…
mryanlo Feb 19, 2025
546a79f
add github label issue triage
mryanlo Feb 19, 2025
eab55f2
fix lint issues
mryanlo Feb 20, 2025
31c12f7
fix github labeler triage bug by adding the github label method to cl…
mryanlo Feb 20, 2025
cd6c6f9
update codeowners
mryanlo Feb 25, 2025
4dbcf64
change resource logic to poll for create and update functions
mryanlo Feb 28, 2025
41e54a3
fix build
mryanlo Feb 28, 2025
f012f22
remove comments
mryanlo Mar 5, 2025
e99843e
revert getok() logic to get tests working again
mryanlo Mar 28, 2025
5b5b9f6
Make tests create all AIO Cluster infrastructure (flakey) (#1)
mryanlo Mar 28, 2025
80ced11
first attempt at directly sshing from PreConfig in go that works
mryanlo Mar 27, 2025
2f582f1
polish and combine steps to make easier to read
mryanlo Mar 27, 2025
2dd9476
make object id an env variable param, move asset tests to have precon…
mryanlo Mar 28, 2025
61e0e19
remove fmt.printf logs
mryanlo Mar 28, 2025
2529809
add comments explaining the steps, add readme to explain overall test…
mryanlo Mar 28, 2025
b8a985e
lint
mryanlo Mar 28, 2025
bd986d5
revert code owners
mryanlo May 12, 2025
94a7d46
Apply suggestions from code review - changes to client.go
mryanlo May 12, 2025
79095c2
Merge branch 'rylo/adr-terraform' of https://github.com/mryanlo/terra…
mryanlo May 12, 2025
ea29647
fix build errors from changing client names to plural. force new true…
mryanlo May 12, 2025
da4e5f2
rename aep files to match correct format
mryanlo May 12, 2025
c8964b6
make array items singular in name for terraform contract, change name…
mryanlo May 13, 2025
6f1bdd5
use resource group id to parse ID
mryanlo May 13, 2025
db6eed0
change terraform "ref"s to "reference"s in asset resource
mryanlo May 13, 2025
0df4e45
fix build errors, move aep authentication to nested blocks for simple…
mryanlo May 13, 2025
dd62eb3
change discovered asset endpoint profile ref to references in AEP
mryanlo May 13, 2025
2978fe9
fix build error with auth in AEP
mryanlo May 13, 2025
adbfcf2
change topic to be block type
mryanlo May 13, 2025
6f2561f
lint
mryanlo May 13, 2025
9e7209e
lint
mryanlo May 13, 2025
d9e9940
update the tests for assets
mryanlo May 13, 2025
a8764fc
make credential blocks singular
mryanlo May 13, 2025
062bd0e
move extended location name to ext location id and remove ext locatio…
mryanlo May 13, 2025
88c71ff
change resource group name to id in tests
mryanlo May 13, 2025
a977f45
update aep test
mryanlo May 14, 2025
79286be
fix test checks
mryanlo May 14, 2025
e860ff2
fix aep test
mryanlo May 15, 2025
7d7948e
fix asset update logic
mryanlo May 15, 2025
b207ce9
add custom location validation for extended location id, change crede…
mryanlo May 15, 2025
26534f0
remove nested blocks from aep authorization block
mryanlo May 15, 2025
00a684f
fix test aep
mryanlo May 15, 2025
3afd2f4
fix aep update test
mryanlo May 15, 2025
8f8c880
lint
mryanlo May 16, 2025
6ecc308
more lint changes
mryanlo May 16, 2025
a932fe3
documentation asset change
mryanlo May 27, 2025
8970324
fix paths set by gitbash and change aep documentation
mryanlo May 27, 2025
3c5e495
lint
mryanlo May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ service/datadog:
service/dev-center:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dev_center((.|\n)*)###'

service/deviceregistry:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_device_registry_asset((.|\n)*)###'

service/devtestlabs:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dev_test_((.|\n)*)###'

Expand Down
5 changes: 5 additions & 0 deletions .github/labeler-pull-request-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ service/dev-center:
- any-glob-to-any-file:
- internal/services/devcenter/**/*

service/deviceregistry:
- changed-files:
- any-glob-to-any-file:
- internal/services/deviceregistry/**/*

service/devtestlabs:
- changed-files:
- any-glob-to-any-file:
Expand Down
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var services = mapOf(
"desktopvirtualization" to "Desktop Virtualization",
"devcenter" to "Dev Center",
"devtestlabs" to "Dev Test",
"deviceregistry" to "Device Registry",
"digitaltwins" to "Digital Twins",
"domainservices" to "DomainServices",
"dynatrace" to "Dynatrace",
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @hashicorp/terraform-azure
* @hashicorp/terraform-azure
5 changes: 5 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
dataprotection "github.com/hashicorp/terraform-provider-azurerm/internal/services/dataprotection/client"
datashare "github.com/hashicorp/terraform-provider-azurerm/internal/services/datashare/client"
desktopvirtualization "github.com/hashicorp/terraform-provider-azurerm/internal/services/desktopvirtualization/client"
deviceregistry "github.com/hashicorp/terraform-provider-azurerm/internal/services/deviceregistry/client"
devtestlabs "github.com/hashicorp/terraform-provider-azurerm/internal/services/devtestlabs/client"
digitaltwins "github.com/hashicorp/terraform-provider-azurerm/internal/services/digitaltwins/client"
dns "github.com/hashicorp/terraform-provider-azurerm/internal/services/dns/client"
Expand Down Expand Up @@ -199,6 +200,7 @@ type Client struct {
DataProtection *dataprotection.Client
DataShare *datashare.Client
DesktopVirtualization *desktopvirtualization.Client
DeviceRegistry *deviceregistry.Client
DevTestLabs *devtestlabs.Client
DigitalTwins *digitaltwins.Client
Dns *dns_v2018_05_01.Client
Expand Down Expand Up @@ -421,6 +423,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
if client.DesktopVirtualization, err = desktopvirtualization.NewClient(o); err != nil {
return fmt.Errorf("building clients for DesktopVirtualization: %+v", err)
}
if client.DeviceRegistry, err = deviceregistry.NewClient(o); err != nil {
return fmt.Errorf("building clients for DeviceRegistry: %+v", err)
}
if client.DevTestLabs, err = devtestlabs.NewClient(o); err != nil {
return fmt.Errorf("building clients for DevTestLabs: %+v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/dataprotection"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datashare"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/desktopvirtualization"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/deviceregistry"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/devtestlabs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/digitaltwins"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/dns"
Expand Down Expand Up @@ -167,6 +168,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
datafactory.Registration{},
dataprotection.Registration{},
desktopvirtualization.Registration{},
deviceregistry.Registration{},
digitaltwins.Registration{},
dns.Registration{},
domainservices.Registration{},
Expand Down
55 changes: 55 additions & 0 deletions internal/services/deviceregistry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Overview of Device Registry Acceptance Tests
===
The Azure Device Registry service has several arc-enabled resources, including Assets and Asset Endpoint Profiles (AEPs). These resources will only create successfully if there is an arc-enabled Kubernetes Cluster in Azure that runs all of Azure IoT Operations' (AIO) service and has a corresponding Custom Location. You can learn more about AIO [here](https://learn.microsoft.com/en-us/azure/iot-operations/). Because of this requirement, this makes acceptance testing Assets and AEP resources more complex since the tests must setup an AIO cluster.

The solution that we have adapts that from the [Custom Location tests](https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/services/extendedlocation/extended_location_custom_location_test.go), but it is a little more complex. Here is an overview of the process the Device Registry tests need to do:
1. First, each of the Device Registry acceptance tests apply a Terraform template to create an Azure Linux VM and all of the VM's infrastructure resources (e.g. public IP address, subnet, the resource group that will hold everything, etc). The VM will host the AIO cluster. The tests will also provision a bash script file to the VM which will execute all the commands needed to setup the AIO cluster. The bash script Terraform template file is [setup_aio_cluster.sh.tftpl](./testdata/setup_aio_cluster.sh.tftpl) and can be found in the `testdata` directory. The tests do not run the bash script yet.

2. Before the Assets/AEPs resources are created, a `PreConfig` step is run. The tests execute some Go code to fetch the VM's public IP address and then uses the IP address to SSH into the VM and execute the bash script on the VM. The bash script will install Azure CLI and setup a [K3s cluster](https://k3s.io/) on the VM, and then run the AZ CLI commands from this [AIO quickstart](https://learn.microsoft.com/en-us/azure/iot-operations/get-started-end-to-end-sample/quickstart-deploy) to arc-enable the cluster and setup AIO services on it (which will also create the Custom Location).
- We must do it this way because even with the `depends_on` property, the tests do not wait for the VM to finish its `remote-exec` to run the bash script. Thus, the tests will fail as they will try to create Assets/AEPs while the AIO cluster and Custom Location are provisioning, throwing a "Custom Location (or other AIO resource) does not exist" error. This is the only way to sequentially execute the bash script to setup the AIO cluster and block the tests from prematurely creating the Asset/AEPs, as attempts to use `null_resource`, Go's `time.sleep()`, etc ended up not working (and stopped `remote-exec` from completing). Also, setting a time limit to wait for the cluster to finish is not recommended as the time to finish script execution can take anywhere between 2000-3500 seconds or even more.

3. Once the bash script completes execution, then the rest of the test proceeds as normal; the test creates the Asset/AEP on the AIO cluster. Note: each resource's test scenarios currently creates a separate AIO cluster for each test scenario. So please make sure the Azure subscription has enough resources to concurrently create multiple VMs.

4. When a test scenario finishes, the cleanup steps will run. The VM, Asset/AEP resource, and other VM infra resources will automatically be destroyed by the test cleanup. However, the AIO cluster and its own resources were created by the VM, not Terraform, so they would not get targeted for deletion by the tests. Fortunately, the tests created the resource group that contains all of these resources. So we specify to the acceptance tests to delete the entire resource group to cleanup the AIO cluster resources, as well. That is why the `prevent_deletion_if_contains_resources` flag is set to false in the tests:
```
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
```

How to run Device Registry Acceptance Tests
===
1. On your own machine, login to Azure CLI as a user with ownership permissions of the Azure subscription the acceptance tests will run on.

2. Run the following commands to enable the providers in your Azure subscription so that the AIO Cluster setup steps will not fail. You only have to do this once for your subscription and after that you can skip this step.
```bash
az provider register -n "Microsoft.ExtendedLocation"
az provider register -n "Microsoft.Kubernetes"
az provider register -n "Microsoft.KubernetesConfiguration"
az provider register -n "Microsoft.IoTOperations"
az provider register -n "Microsoft.DeviceRegistry"
az provider register -n "Microsoft.SecretSyncController"
```

3. Run `az ad sp show --id bc313c14-388c-4e7d-a58e-70017303ee3b --query id -o tsv` to get the Custom Location RP's Entra App Object ID. Store it in an environment variable `ARM_ENTRA_APP_OBJECT_ID` (`export ARM_ENTRA_APP_OBJECT_ID=<object ID>`). In theory, you only need to run the `az ad sp show` command once because once you have the object ID, you can reuse that object ID in the acceptance test pipeline for future test runs.

4. The following environment variables need to be set to run the Acceptance Tests. Make sure that the Service Principal running the tests has ownership permissions of the subscription so that the Azure CLI commands in the setup script do not fail.
```bash
# ID of the Azure subscription that the acceptance tests will run on
export ARM_SUBSCRIPTION_ID=<subscription ID>

# The Client ID of the Service Principal that will run the acceptance tests.
export ARM_CLIENT_ID=<client ID>

# The password of the Service Principal that will run the acceptance tests.
export ARM_CLIENT_SECRET=<client secret>

# The Object ID of the Custom Locations RP's Entra App, as mentioned in previous step.
export ARM_ENTRA_APP_OBJECT_ID=<object ID>
```

5. Run the acceptance tests as normal.
33 changes: 33 additions & 0 deletions internal/services/deviceregistry/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package client

import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/deviceregistry/2024-11-01/assetendpointprofiles"
"github.com/hashicorp/go-azure-sdk/resource-manager/deviceregistry/2024-11-01/assets"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
AssetsClient *assets.AssetsClient
AssetEndpointProfilesClient *assetendpointprofiles.AssetEndpointProfilesClient
}

func NewClient(o *common.ClientOptions) (*Client, error) {
assetsClient, err := assets.NewAssetsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Assets Client: %+v", err)
}
o.Configure(assetsClient.Client, o.Authorizers.ResourceManager)

assetEndpointProfilesClient, err := assetendpointprofiles.NewAssetEndpointProfilesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Asset Endpoint Profiles Client: %+v", err)
}
o.Configure(assetEndpointProfilesClient.Client, o.Authorizers.ResourceManager)

return &Client{
AssetsClient: assetsClient,
AssetEndpointProfilesClient: assetEndpointProfilesClient,
}, nil
}
Loading
Loading