Skip to content

Add terraform module for azure auto discovery#62145

Open
avatus wants to merge 11 commits intomasterfrom
avatus/azuremodule
Open

Add terraform module for azure auto discovery#62145
avatus wants to merge 11 commits intomasterfrom
avatus/azuremodule

Conversation

@avatus
Copy link
Contributor

@avatus avatus commented Dec 10, 2025

This will add a terraform module that will support the automatic discovery of VMs in azure, using an OIDC integration.

Closes #60818

Changelog: Added a terraform module to support automatic discovery of azure resources.

@avatus avatus requested review from greedy52 and removed request for espadolini and flyinghermit December 10, 2025 20:46
@avatus avatus force-pushed the avatus/azuremodule branch from 3f101f4 to 082b786 Compare December 10, 2025 23:28
Comment on lines +5 to +10
- Azure user-assigned managed identity for Teleport Discovery Service to use.
- Azure federated identity credential that trusts the Teleport proxy as an issuer.
- Azure custom role definition and assignment that grant the minimum VM discovery and install permissions.
- Teleport `discovery_config` cluster resource that configures Teleport for Azure VM discovery.
- Teleport `integration` cluster resource for Azure OIDC.
- Teleport `token` cluster resource that allows Teleport nodes to join the cluster using Azure credentials.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add short explanation how each of those resources will be used. For example, we say that we need user-assigned managed identity for Discovery Service, but we are not explaining how will that account be used exactly.

Having the purpose explained helps to ensure proper understanding.

Copy link
Contributor

@hugoShaka hugoShaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no Terraform expert but this looks ok.

Can we make sure that:

  • this code is linted with tf lint and the CI enforces it
  • there is a clear owner of the module and it is covered by the test plan

We had other TF modules in the past that went unmainted and I had to remove. My main concern is that this does not follow the same path. I'd like us to ensure the same quality/support level as the go code we write.

@avatus
Copy link
Contributor Author

avatus commented Dec 16, 2025

@hugoShaka agreed.

this code is linted with tf lint and the CI enforces it

i believe this is enforced with tflint because it was throwing errors already until i fixed them. so we're good there

there is a clear owner of the module and it is covered by the test plan

i like this callout. im happy to be the owner, but im unsure where to specify it. i will update the testplan as well.

This will add a terraform module that will support the automatic
discovery of VMs in azure, using an OIDC integration.

Closes #60818

Changelog: Added a terraform module to support automatic discovery of
azure resources.
- align variable names
- conditional creation
- remove all inputs from the example
@greedy52 greedy52 added the terraform-modules Terraform modules published to Teleport's registry label Jan 26, 2026
Copy link
Contributor

@greedy52 greedy52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any plan to support non-integration discovery?

# optional
match_azure_regions = ["westus", "eastus"] // discover VMs in these US west and east regions.
match_azure_resource_groups = ["*"] // discover VMs in all resource groups
match_azure_tags = { "env" = ["example"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a comment on match_azure_tags.

Comment on lines +9 to +10
azure_managed_identity_location = azurerm_resource_group.example.location
azure_resource_group_name = azurerm_resource_group.example.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not very obvious what these two variables will be used for.

Comment on lines +5 to +6
# Custom role for discovery permissions
resource "azurerm_role_definition" "teleport_discovery" {
Copy link
Contributor

@greedy52 greedy52 Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the resource preventing support for multi subscriptions? this is fine for now but i think we will eventually revisit this when working on "org" level discovery for azure.

spec = {
azure = {
allow = [{
subscription = local.azure_subscription_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we set resource group?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because the VMs we discover won't necessarily be in the same resource group as the identity/role for discovery service

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about match_azure_resource_groups?

Copy link
Contributor

@GavinFrazar GavinFrazar Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. I guess we can use that, but it will require a code change because discovery supports wildcard resource group matcher and join tokens do not

@greedy52 greedy52 requested review from greedy52 and hugoShaka March 6, 2026 14:26
@greedy52
Copy link
Contributor

greedy52 commented Mar 6, 2026

could we provide a manual test plan for this PR? @GavinFrazar do you prefer updating this one or maybe opening a new PR as you?

@GavinFrazar
Copy link
Contributor

could we provide a manual test plan for this PR? @GavinFrazar do you prefer updating this one or maybe opening a new PR as you?

I'll provide a manual test plan and keep updating this PR

@r0mant r0mant assigned alexhemard and unassigned GavinFrazar Mar 12, 2026
Remove unsupported argument "resource_group_name".
It's not useful to output this.
This permission will be used by:
1. discovery service to perform wildcard subscription discovery
2. auth service to perform wildcard subscription VM join validation
It's so cheap to read the data source that we don't need to make it
conditional and it improves the terraform plan.
In order to discover VMs in all subscriptions, the module must allow the
user to configure the role and role assignment scopes.

Additionally, the module must allow the user to specify the
subscription(s) which should be discovered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure backport/branch/v18 discovery size/md terraform-modules Terraform modules published to Teleport's registry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Terraform module for auto-discovery in 1 Azure account

6 participants