Hey azure peeps, Have any of you guys used pulumi ...
# azure
b
Hey azure peeps, Have any of you guys used pulumi to create a new subscription and then create resources inside that newly created subscription ? Anyone got any example code or links to any repos ?
a
You can do that using the Azure Classic provider's azure.core.Subscription. You'll have to provide billing account values found under
Cost Management + Billing
-
Billing Scopes
-
Properties
Using the following inputs on Subscription:
enrollment_account_name
(Account ID from the properties view)
billing_scope_id
(Billing Account ID from the properties view) I believe you can only create Subscriptions programmatically when your account is under the Microsoft Customer Agreement (MCA) or Enterprise Agreement (EA) models. I think Pay-as-you-go subscriptions from the Microsoft Online Subscription Agreement can't be provisioned programmatically.
s
I have a .ps1 that creates the subscriptions and provider user in entra id as well as permissions and outputs all the az details into the pulumi secrets... It was a bit chicken and egg when I tried to get pulumi to do it, but that was a while back
b
Awesome, anything in the azure native library ?
a
b
Yeah I see, is it bad practice to mix native and classic ?
a
I personally only use classic for these rare cases but stick to native for everything else. It shouldn't have any implications and you can use outputs as inputs across any provider. You'll just have to configure both providers.
b
Ok great thanks. I'll have a play around
do you know how to dispatch the subscription to the subsequent resources by chance? Say
Copy code
sub = azure.core.Subscription(...)
rg = azure.resources.ResourceGroup( how do i create this in the above subsription ?)
a
You'd explicitly initialize a Provider using the new subscription ID output. Demonstrating subscription provisioning via azure-classic and usage in azure-native.
Copy code
from pulumi_azure_native import Provider

sub = azure.core.Subscription(...)
new_provider = Provider(
  subscription_id=sub.subscription_id,
  ...
)
Then to use that provider for resource creation:
Copy code
SomeResource(
  ...,
  opts=pulumi.ResourceOptions(provider=new_provider)
)
You can also consider creating a subscription within one Pulumi project, exporting the subscription details as outputs and use stack references in downstream projects. This blog post by @billowy-army-68599 provides good advise on how to layer IaC projects which f.x. recommends splitting up resources by their rate of change with subscriptions probably being among the rarest resource you'd make frequent changes to.
b
yeah nice one mate. cheers