When you need to deploy from VSTS (VisualStudio.com) either via a build or via the release pipeline, you need a service principal that allows VSTS to access your Azure subscription. When the Azure subscription is connected directly to your VSTS account, you can use the simple version of the “New Service Endpoint” dialog. But, if the VSTS or Azure subscriptions are disconnected, then you need to use the full version of the “New Service Endpoint” dialog. This post goes into how you can manually do that:
What you need on the Azure side:
- Azure Active Directory instance. If you dont have one, create it. The free tier will do.
- After you create the AAD instance, open the AAD resource and select “Properties”. Copy the value for “Directory Id”.
Make sure “Microsoft Visual Studio Team Services” is registered as an Enterprise Application:Go to Azure Active Directory >> Enterprise Application.If “Microsoft Visual Studio Team Services” does not appear in the list of “All Applications”, click on “New Application” and then search for “Microsoft Visual Studio Team Services” and add it. This will add “Microsoft Visual Studio Team Services (Microsoft Visual Studio Online)” to the list of APIs you can authorize your SP to have access to (used below in step 3-8)- The Service Principal is created by creating an “App Registration”.
- Click on “App Registrations” and then “New Application Registration”.
- Enter a name for the App Registration. You need to remember this name.
- Leave type as “web app/API”
- Enter a sign-on URL (it just needs to start with http:// or https://. Doesnt matter and can be any fake URL).
- Open the newly created “App Registration”
- Copy the “Application ID” value.
- Click on settings.
- Click on Required permissions and then, “Add”
- Select “Microsoft Visual Studio Team Services (Microsoft Visual Studio Online)”.
- The permission should be “Have full access to Visual Studio Team Services REST APIs”.
- Click Save.
- Click on Key
- Enter anything for “Key Description”
- Duration can be “Never Expirer”
- When you save, you will see a string value in the “Value” box. Copy and save this value (this is the client secret).
- Provide the service principal you created in step (2) access to your subscription.
- Go to your subscription in Azure portal.
- Choose Access Control
- Click Add and you can provide the SP direct access as a contributor to your subscription. Alternatively:
- You can provide access just to a specific Resource Group, which you can do by opening the RG and then updating the Access Control by providing access to the SP to that RG.
- Note: in a production or a lock down environment, I would provide access to the Service Principal either to a resource group or the resource directly. Providing access directly to the subscription, may allow anybody to deploy and create resources directly in production, which may or may not be ideal for your use-case.
- Also, go to the “Overview” section of your Azure Subscription and copy the “Subscription Id” and Subscription Name
In Visual Studio:
- Open your VSTS project.
- Click on the gear icon at the top and choose “Services”
- Click “New Service Endpoint” and then “Azure Resource Manager”
- At the bottom choose “use the full version of the endpoint dialog”. You should see this dialog:
- Subscription Id: from 3.5
- Subscription Name: from 3.5
- Service Principal Client Id: from 2.6
- Service Principal Key: from 2.10.3
- Tenant Id: from 1.1
Now click on “Verify Connection” and it should come back with a value of “verified”.
No comments:
Post a Comment
Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.