-
Notifications
You must be signed in to change notification settings - Fork 5k
New service: DeviceRegistry + new resources: azurerm_device_registry_asset and azurerm_device_registry_asset_endpoint_profile
#28399
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
Open
mryanlo
wants to merge
74
commits into
hashicorp:main
Choose a base branch
from
mryanlo:rylo/adr-terraform
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.
Open
Changes from 43 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
aab6731
boilerplate service code
mryanlo 4c3f492
boilerplate service package
mryanlo d68570d
AEP resource
mryanlo 9608e73
fix build errors and lints
mryanlo a8d1a18
lint
mryanlo 9397281
cleanup and lint for AEP
mryanlo 96b2367
update aep + asset resource
mryanlo 4c3891e
vendor dependencies
mryanlo 8c9fdd8
update codeowners to add device registry required reviewers for devic…
mryanlo 7a1b1a5
fix build errors in aep and asset resource types
mryanlo 287a79c
remove untyped service
mryanlo 32aced7
run `go generate ./internal/provider`
mryanlo 2033c9a
documentation for asset and AEP resources, removing asset and AEP rea…
mryanlo 6d24814
fix aep resource bugs
mryanlo 3ef00f4
simplify update logic for aep auth methods
mryanlo 54394e5
fix bugs in asset resource
mryanlo bdb3547
documentation example updates
mryanlo 5435de0
remove attributes fields from documentation
mryanlo e3ef30f
rough draft of tests
mryanlo 36600f5
Merge branch 'main' of https://github.com/mryanlo/terraform-provider-…
mryanlo 09a5eb4
add kind.yaml
mryanlo 547600d
snake case aep names to fix validation errors
mryanlo 62e4291
lint
mryanlo 4ec9666
delete aio cluster setup scripts, make asset tests, change aep tests …
mryanlo 505965b
add comment
mryanlo f2669aa
add back documentation uri update asset
mryanlo a38f5c7
fix asset test
mryanlo e877e4f
Merge branch 'main' of https://github.com/mryanlo/terraform-provider-…
mryanlo 546a79f
add github label issue triage
mryanlo eab55f2
fix lint issues
mryanlo 31c12f7
fix github labeler triage bug by adding the github label method to cl…
mryanlo cd6c6f9
update codeowners
mryanlo 4dbcf64
change resource logic to poll for create and update functions
mryanlo 41e54a3
fix build
mryanlo f012f22
remove comments
mryanlo e99843e
revert getok() logic to get tests working again
mryanlo 5b5b9f6
Make tests create all AIO Cluster infrastructure (flakey) (#1)
mryanlo 80ced11
first attempt at directly sshing from PreConfig in go that works
mryanlo 2f582f1
polish and combine steps to make easier to read
mryanlo 2dd9476
make object id an env variable param, move asset tests to have precon…
mryanlo 61e0e19
remove fmt.printf logs
mryanlo 2529809
add comments explaining the steps, add readme to explain overall test…
mryanlo b8a985e
lint
mryanlo bd986d5
revert code owners
mryanlo 94a7d46
Apply suggestions from code review - changes to client.go
mryanlo 79095c2
Merge branch 'rylo/adr-terraform' of https://github.com/mryanlo/terra…
mryanlo ea29647
fix build errors from changing client names to plural. force new true…
mryanlo da4e5f2
rename aep files to match correct format
mryanlo c8964b6
make array items singular in name for terraform contract, change name…
mryanlo 6f1bdd5
use resource group id to parse ID
mryanlo db6eed0
change terraform "ref"s to "reference"s in asset resource
mryanlo 0df4e45
fix build errors, move aep authentication to nested blocks for simple…
mryanlo dd62eb3
change discovered asset endpoint profile ref to references in AEP
mryanlo 2978fe9
fix build error with auth in AEP
mryanlo adbfcf2
change topic to be block type
mryanlo 6f2561f
lint
mryanlo 9e7209e
lint
mryanlo d9e9940
update the tests for assets
mryanlo a8764fc
make credential blocks singular
mryanlo 062bd0e
move extended location name to ext location id and remove ext locatio…
mryanlo 88c71ff
change resource group name to id in tests
mryanlo a977f45
update aep test
mryanlo 79286be
fix test checks
mryanlo e860ff2
fix aep test
mryanlo 7d7948e
fix asset update logic
mryanlo b207ce9
add custom location validation for extended location id, change crede…
mryanlo 26534f0
remove nested blocks from aep authorization block
mryanlo 00a684f
fix test aep
mryanlo 3afd2f4
fix aep update test
mryanlo 8f8c880
lint
mryanlo 6ecc308
more lint changes
mryanlo a932fe3
documentation asset change
mryanlo 8970324
fix paths set by gitbash and change aep documentation
mryanlo 3c5e495
lint
mryanlo 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
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| * @hashicorp/terraform-azure | ||
|
|
||
| # PRLabel: %Device Registry | ||
| /internal/services/deviceregistry/ @marcodalessandro @rohankhandelwal @riteshrao @davidemontanari | ||
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 |
|---|---|---|
| @@ -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. |
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,34 @@ | ||
| 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" | ||
|
|
||
mryanlo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
| ) | ||
|
|
||
| type Client struct { | ||
| AssetClient *assets.AssetsClient | ||
| AssetEndpointProfileClient *assetendpointprofiles.AssetEndpointProfilesClient | ||
mryanlo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func NewClient(o *common.ClientOptions) (*Client, error) { | ||
| assetEndpointProfileClient, err := assetendpointprofiles.NewAssetEndpointProfilesClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("creating AssetEndpointProfiles Client: %+v", err) | ||
| } | ||
| o.Configure(assetEndpointProfileClient.Client, o.Authorizers.ResourceManager) | ||
|
|
||
| assetClient, err := assets.NewAssetsClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("creating Asset Client: %+v", err) | ||
| } | ||
| o.Configure(assetClient.Client, o.Authorizers.ResourceManager) | ||
mryanlo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return &Client{ | ||
| AssetClient: assetClient, | ||
| AssetEndpointProfileClient: assetEndpointProfileClient, | ||
mryanlo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, nil | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.