Use Azure Entra Authentication provider in template
Recently I've had the idea to provide a template that our developers can then use to create a specific resource configuration in their own subscriptions to test as close to production as possible. To do this my idea was to use the access token via coder_external auth and then use this in a azurerm_provider block:
however, when I try to build the template I run into multiple issues:
1. the subscription id is empty when trying to build (obviously as it comes from the parameter)
2. when supplying a default subscription id, the next error is Error: unable to build authorizer for Resource Manager API: could not configure AzureCli Authorizer: could not parse Azure CLI version: launching Azure CLI: exec: "az": executable file not found in $PATH
on main.tf line 32, in provider "azurerm":
the second error sounds like it cannot authenticate and then tries to fall back to cli authentication.
I've also tried to submit a hard coded token I've created before using powershell but that token also did not work and resulted in the same error.
Am I fundamentally misunderstanding something here?
And how would I correctly create the template I'm thinking about?
26 Replies
<#1344606210602700800>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
hey, i don't think this is possible when using providers
i've tried that in the past but provisioners are being loaded before any other resources, which means that the data is going to be empty
ah thats unfortunate. was hoping to avoid creating arm templates for this and instead use coder for the many features it provides. do you have an idea how I could reach this using coder?
GitHub
Provider configuration cannot depend on data sources during import ...
As documented in Import: Provider Configuration, a provider used during import cannot depend on data sources for its configuration*. As of v0.14, data sources can now be handled entirely during pla...
But I'm doing this in some (non-coder) terraform repositories. It usually works fine unless the data does not have a value
i think you would need to either use a central azure subscription or have devs input the data manually
I have a central azure tenant, but the devs have their own subscriptions
hmm, i am not sure then, i've never got it to work in Coder and assumed it was a terraform thing honestly
yeah i've used the wrong wording sorry
no worries
is there any way you could be able to not use per-dev subscriptions maybe?
the main goal was to utilize the free azure budget each developer gets with their MSDN subscriptions. Sure I can also do it in one subscription but then I would have to pay the bill
makes sense
it seems you should be able to work around this by setting it in a
local
variable first
i haven't tested it thoughI also tried it with hard coded values instead of the parameter and the token from the external auth, I've ran into the same issue there
I just tried it with the locals, also comes to the same error
What is the intentional use of coder_external_auth? I don't quite get it from the documentation
It allows to get tokens for services via OAuth, like you're doing
usually you'd use it to connect to the GitHub CLI, an Artifactory instance or something else
ah I understand. so nothing to be used in the terraform code directly but on the data plane
you can use it inside the terraform code directly but providers are handled in a specific way within terraform
it really depends on what you want to do with the token, most of the time you're just passing it down to the container/pod you're provisioning
Okay, thank you. I'll have to look somewhere else for this use case then. Coder itself is great though and saves us a lot of work in other cases
most of the time if you can achieve it with terraform you should be able to do it with Coder as well, i'm just not really sure of the specifics there and can't find anything meaningful online
as for this, i haven't used the Azure provider a lot the config seems correct to me, so i'm not sure
how are you setting the default value?
you mean for the subscription_id? in the parameter:
maybe try using
coalesce
instead
I also tried something like this with I token I created via powershell
given the provider block loads early, maybe the default isn't set yet somehow
might of course also be the case that my entra app gives me a token that is not permitted to that, or I'm doing something really wrong in the provider config, I can't rule that out
hey, were you able to figure this out?
Unfortunately haven't had the time to invest more into this
But the approach will most likely be that we have a principal that developers have to enroll to their subscription. Then we deploy via that principal. I'll let you know when I find time to set this up
sounds good!