SlideShare une entreprise Scribd logo
1  sur  47
Automating Your Azure
Environment
Michael S. Collier
Cloud Solution Architect,
Microsoft
Level: Intermediate
Michael S. Collier
Cloud Solution Architect
Microsoft
michael.collier@microsoft.com
@MichaelCollier
www.MichaelSCollier.com
http://aka.ms/csablog
http://aka.ms/fundamentalsofazure
Today’s Agenda
1. Why Automation in Azure?
2. Azure Management Library
3. Azure PowerShell
a) Azure Service Management
b) Azure Resource Manager
4. Azure Automation
Why Automate in Azure?
Why Automation?
• Time to provision full environments
– Compute, storage, etc.
• Deployment to multiple geographies
– Change only configuration / parameters
Why Automation?
#1 source of failed projects (IMO)
Humans TERRIBLE at repetitive
tasks
A Few Options
REST API
• Service
Management
• Resource
Manager
A Few Options
REST API
• Service
Management
• Resource
Manager
Azure
Management
Library
A Few Options
REST API
• Service
Management
• Resource Manager
Azure
Management
Library
PowerShell
• Invoke REST
• Service
Management
• Resource Manager
A Few Options
REST API
• Service
Management
• Resource Manager
Azure
Management
Library
PowerShell
• Invoke REST
• Service
Management
• Resource Manager
XPlat CLI
• ??
A Few Options
REST API
• Service
Management
• Resource Manager
Azure
Management
Library
PowerShell
• Invoke REST
• Service
Management
• Resource Manager
XPlat CLI
• ??
Azure
Automation
A Few Options
REST API
• Service
Management
• Resource Manager
Azure
Management
Library
PowerShell
• Invoke REST
• Service
Management
• Resource Manager
XPlat CLI
• ??
Azure
Automation
Azure Management
Library
Azure Management Library
• Consistent modern libraries over the Azure
REST API
– NET, Java, Python, Go, & Ruby
Azure Management Library
Azure Management Library
• Scenarios
– Integration Testing
– Custom provisioning of services (SaaS)
– Dev/Test
– Resource Governance
• Almost anything you may want to automate
Azure Management Library
• Microsoft.WindowsAzure.*
– Older RDFE version
– Not recommended
• Microsoft.Azure.*
– Based on new Azure Resource Manager (ARM)
– Recommended
Azure Management Library
• Get all or
just the ones
you need
Authentication
• Azure Active Directory
• Create a service principal
– Password (PowerShell or CLI)
– Certificate (PowerShell)
• Assign necessary ROLE to the service principal
Create the Service Principal
Switch-AzureMode AzureResourceManager
Select-AzureSubscription -SubscriptionName “My MSDN Azure”
$appName = "VSLiveNYC2015"
$appHomePage = "http://localhost"
$appUri = "http://localhost"
$pwd = "test!123"
# Create a new Azure AD application
$azureAdApp = New-AzureADApplication -DisplayName $appName -HomePage $appHomePage -IdentifierUris $appUri -Password $pwd -Verbose
# Create a service principal
New-AzureADServicePrincipal -ApplicationId $azureAdApp.ApplicationId
# Assign a role to the service principal
New-AzureRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $azureAdApp.ApplicationId
# Get the subscription for the role assignment
$subscription = Get-AzureSubscription | where { $_.IsCurrent }
# Create a new credential object to contain the credentials
$creds = Get-Credential -UserName $azureAdApp.ApplicationId -Message "enter your creds"
Add-AzureAccount -Credential $creds -ServicePrincipal -Tenant $subscription.TenantId
Get this at http://aka.ms/uognfb
Get the Authentication Token
private const string SubscriptionId = “[YOUR_AZURE_SUBSCRIPTION_ID]";
private const string TenantId = “[YOUR_AZURE_AD_TENANT_ID]";
private const string ApplicationId = “[YOUR_NEWLY_REGISTERED_APP_id]";
private const string ApplicationPwd = "test!123";
public static string GetAToken()
{
var authenticationContext = new AuthenticationContext(string.Format("https://login.windows.net/{0}", TenantId));
var credential = new ClientCredential(clientId: ApplicationId, clientSecret: ApplicationPwd);
var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential);
if (result == null)
{
throw new InvalidOperationException("Failed to obtain the JWT token");
}
string token = result.AccessToken;
return token;
}
Get this at http://aka.ms/uognfb
Demo
Authenticate and Browse
Demo Recap
1. Create a Service Principal in Azure AD
2. Get the JWT authentication token
3. Create a credential object with token and
subscription
4. Create a resource client
5. Execute actions against the client
PowerShell Cmdlets
• Get the goods
http://azure.microsoft.com/en-us/downloads/ https://github.com/Azure/azure-powershell/releases

PowerShell
• Use cmdlets and/or REST APIs
• Ability to script complex environments
– Template with an XML parameters file
– PowerShell learning curve
– Your responsibility to handle errors & ensure
consistency
• Consistent Deployments
– Build server or developer machine
Authentication Options
• Interactive
– Azure AD
PS C:> Add-AzureAccount
C:Users<user>AppDataRoamingWindows Azure Powershell
Authentication Options
• Interactive
– Azure AD
PS C:> Add-AzureAccount
VERBOSE: Account "michael.collier@live.com" has been added.
VERBOSE: Subscription "MSFT Azure Internal - Collier" is selected as the default subscription.
VERBOSE: To view all the subscriptions, please use Get-AzureSubscription.
VERBOSE: To switch to a different subscription, please use Select-AzureSubscription.
Id Type Subscriptions Tenants
-- ---- ------------- -------
michael.collier@live.com User 0bbbc191-0023-aaaa-yyyy-xxxxxxxxxxxx 9b6b07ee-3eb1-aaaa-yyyy-xxxxxxxxxxxx
278b93db-29ab-aaaa-yyyy-xxxxxxxxxxxx 715f4ed0-544a-aaaa-yyyy-xxxxxxxxxxxx
3acf171d-3d34-aaaa-yyyy-xxxxxxxxxxxx 72f988bf-86f1-aaaa-yyyy-xxxxxxxxxxxx
c68d7703-d6ed-aaaa-yyyy-xxxxxxxxxxxx 20acfbf0-4318-aaaa-yyyy-xxxxxxxxxxxx
57c8cb4e-3ce2-aaaa-yyyy-xxxxxxxxxxxx a28aed54-1dc8-aaaa-yyyy-xxxxxxxxxxxx
b5fb8dfb-3e0b-aaaa-yyyy-xxxxxxxxxxxx 362755da-bfb2-aaaa-yyyy-xxxxxxxxxxxx
9a94b816-e790-aaaa-yyyy-xxxxxxxxxxxx 7805bdb6-17da-aaaa-yyyy-xxxxxxxxxxxx
cd978409-0ac9-aaaa-yyyy-xxxxxxxxxxxx
C:Users<user>AppDataRoamingWindows Azure Powershell
Authentication Options
• Programmatic
– Management certificate
– New –credentials option
$userName = "<your work/school account user name>"
$securePassword = ConvertTo-SecureString -String "<your work/school account password>" -
AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($userName,
$securePassword)
Add-AzureAccount -Credential $cred
Demo
Create a VM with Custom Script Extension
Deploy a Cloud Service
Demo Recap
1. Authenticate PowerShell with Azure
2. Upload to blob storage a .ps1 script to format
drives
3. Provision new Azure VM via PowerShell.
a) Custom script extension to format data disks
4. Create Cloud Service (web role) project
5. PowerShell script to upload and deploy
Azure Resource Manager
What is Azure Resource Manager?
Unit of Management
• Lifecycle
• Identity
• Grouping
One Resource -> One Resource Group
ARM Benefits
Desired-state deployment
Faster deployment
Role-based access control (RBAC)
Resource-provider model
Orchestration
Resource configuration
SQL - A Website Virtual
Machines
SQL-A
Website
[SQL CONFIG] VM (2x)
DEPENDS ON SQLDEPENDS ON SQL
SQLCONFIG
Image source - http://channel9.msdn.com/Events/Build/2014/2-607
Consistent Management Layer
Resource
Provider
https://management.azure.com/subscriptions/{{subscriptionId}}/provide
rs?api-version={{apiVersion}}
?
REST API
ARM Functions
ARM Templates supports small set of built-in functions
parameters, variables
reference, resourceGroup, resourceId
base64, concat, padLeft, padLeft, replace, toLower, toUpper
deployment, provider, subscription
listKeys
Not supported
User-defined functions
Control constructs – if, while, etc.
Loops and Nested Templates
Loops
Provide basic copy capability
Useful in cloning resource configuration
For example, deploying multiple VMs
Nested Templates
One template can invoke another
Simplifies creation of sophisticated templates
Supports parameters
Supports output variables
ARM Deployment Logs
Logs
Provider
Resource group
Resource
Availability
Kept for 15 days
Default is last hour (PowerShell)
Filter by Status e.g., Failed
PowerShell
Get-AzureResourceProviderLog
Get-AzureResourceGroupLog
Get-AzureResourceLog
Demo
Create a new Azure Web App + SQL DB
Demo Recap
1. Get latest Azure SDK for Visual Studio
2. Create new ‘Azure Resource Group’ project
3. Add Web App + SQL template
4. Provide parameters
5. Deploy via PowerShell
What is Azure Automation?
• IT process automation solution for Azure
– Creation, monitoring, deployment, &
maintenance
– Runbooks & Assets
– Leverage existing PowerShell scripts
Runbook Types
• PowerShell Workflow
– Windows Workflow Foundation
• Checkpoint, suspend, & resume
– Parallel or serial execution
– Compilation (time increases as complexity increases)
• PowerShell (native)
– No checkpoint, suspend, or resume
– Serial execution only
– No compile step! Fast!
Demo
Stop VMs nightly
Demo Recap
1. Create Azure Automation account
a) Create an AAD user for Azure Automation
b) Create an Azure Connection Asset
2. Create Runbook to Stop VMs
1. Connect to Azure subscription
2. Iterate over all services and VMs
3. Test Runbook
4. Publish Runbook
5. Link Runbook to a Schedule
Choices . . . When to Use
Resources
• Azure Resource Manager Preview SDKs
– https://azure.microsoft.com/en-us/blog/azure-resource-manager-preview-sdks/
• Authenticating a service principal with Azure Resource Manager
– https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-
service-principal/
• Keith Mayer’s blog posts on Azure Automation
– http://blogs.technet.com/b/keithmayer/archive/2014/04/04/step-by-step-getting-started-
with-windows-azure-automation.aspx
Questions?
Thank You!
Michael S. Collier
@MichaelCollier | www.michaelscollier.com
michaelscollier@gmail.com | michael.collier@microsoft.com

Contenu connexe

Tendances

What's New for the Windows Azure Developer? Lots! (July 2013)
What's New for the Windows Azure Developer?  Lots! (July 2013)What's New for the Windows Azure Developer?  Lots! (July 2013)
What's New for the Windows Azure Developer? Lots! (July 2013)
Michael Collier
 

Tendances (20)

What's New for the Windows Azure Developer? Lots! (July 2013)
What's New for the Windows Azure Developer?  Lots! (July 2013)What's New for the Windows Azure Developer?  Lots! (July 2013)
What's New for the Windows Azure Developer? Lots! (July 2013)
 
Windows Azure for Developers - Building Block Services
Windows Azure for Developers - Building Block ServicesWindows Azure for Developers - Building Block Services
Windows Azure for Developers - Building Block Services
 
Inside Azure Resource Manager
Inside Azure Resource ManagerInside Azure Resource Manager
Inside Azure Resource Manager
 
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
 
Inside Azure Diagnostics
Inside Azure DiagnosticsInside Azure Diagnostics
Inside Azure Diagnostics
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
 
Infrastructure as Code for Beginners
Infrastructure as Code for BeginnersInfrastructure as Code for Beginners
Infrastructure as Code for Beginners
 
Monitoring Containers at Scale - September Webinar Series
Monitoring Containers at Scale - September Webinar SeriesMonitoring Containers at Scale - September Webinar Series
Monitoring Containers at Scale - September Webinar Series
 
AWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar SeriesAWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar Series
 
Running Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic BeanstalkRunning Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic Beanstalk
 
Deep Dive:EC2 Container Service
Deep Dive:EC2 Container ServiceDeep Dive:EC2 Container Service
Deep Dive:EC2 Container Service
 
Deep Dive - Infrastructure as Code
Deep Dive - Infrastructure as CodeDeep Dive - Infrastructure as Code
Deep Dive - Infrastructure as Code
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container DayECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
ECS & ECR Deep Dive - 김기완 솔루션즈 아키텍트 :: AWS Container Day
 
Building infrastructure with Azure Resource Manager using PowerShell
Building infrastructure with Azure Resource Manager using PowerShell Building infrastructure with Azure Resource Manager using PowerShell
Building infrastructure with Azure Resource Manager using PowerShell
 
10 Ways to Gaurantee Your Azure Project will Fail
10 Ways to Gaurantee Your Azure Project will Fail10 Ways to Gaurantee Your Azure Project will Fail
10 Ways to Gaurantee Your Azure Project will Fail
 
EC2 Container Service - Distributed Applications at Scale - Pop-up Loft Tel Aviv
EC2 Container Service - Distributed Applications at Scale - Pop-up Loft Tel AvivEC2 Container Service - Distributed Applications at Scale - Pop-up Loft Tel Aviv
EC2 Container Service - Distributed Applications at Scale - Pop-up Loft Tel Aviv
 
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
 
Amazon EC2:Masterclass
Amazon EC2:MasterclassAmazon EC2:Masterclass
Amazon EC2:Masterclass
 
Make Web, Not War - Installfest: Extend Your Web Server, Rodney Buike
Make Web, Not War - Installfest: Extend Your Web Server, Rodney BuikeMake Web, Not War - Installfest: Extend Your Web Server, Rodney Buike
Make Web, Not War - Installfest: Extend Your Web Server, Rodney Buike
 

Similaire à Automating Your Azure Environment

Similaire à Automating Your Azure Environment (20)

Strategies to automate deployment and provisioning of Microsoft Azure.
Strategies to automate deployment and provisioning of Microsoft Azure.Strategies to automate deployment and provisioning of Microsoft Azure.
Strategies to automate deployment and provisioning of Microsoft Azure.
 
Azure provisioning at your control
Azure provisioning at your controlAzure provisioning at your control
Azure provisioning at your control
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”
 
Becoming the master of disaster... with asr
Becoming the master of disaster... with asrBecoming the master of disaster... with asr
Becoming the master of disaster... with asr
 
Azure cli-azure devops
Azure cli-azure devopsAzure cli-azure devops
Azure cli-azure devops
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
 
WinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSC
WinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSCWinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSC
WinOps Conf 2016 - Ed Wilson - Configuration Management with Azure DSC
 
New features of Azure Cloud Provider in OpenShift Container Platform 3.10
New features of Azure Cloud Provider in OpenShift Container Platform 3.10New features of Azure Cloud Provider in OpenShift Container Platform 3.10
New features of Azure Cloud Provider in OpenShift Container Platform 3.10
 
AWS Summit Auckland - Introducing Well-Architected for Developers
AWS Summit Auckland  - Introducing Well-Architected for DevelopersAWS Summit Auckland  - Introducing Well-Architected for Developers
AWS Summit Auckland - Introducing Well-Architected for Developers
 
New features of Azure Cloud Provider at OCP 3.10
New features of Azure Cloud Provider at OCP 3.10New features of Azure Cloud Provider at OCP 3.10
New features of Azure Cloud Provider at OCP 3.10
 
Managing Azure Components Using Azure PowerShell
Managing Azure Components Using Azure PowerShellManaging Azure Components Using Azure PowerShell
Managing Azure Components Using Azure PowerShell
 
Microsoft Azure essentials
Microsoft Azure essentialsMicrosoft Azure essentials
Microsoft Azure essentials
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
Zure Azure PaaS Zero to Hero - DevOps training day
Zure Azure PaaS Zero to Hero - DevOps training dayZure Azure PaaS Zero to Hero - DevOps training day
Zure Azure PaaS Zero to Hero - DevOps training day
 
Exam Overview 70-533 Implementing Azure Infrastructure Solutions
Exam Overview 70-533 Implementing Azure Infrastructure SolutionsExam Overview 70-533 Implementing Azure Infrastructure Solutions
Exam Overview 70-533 Implementing Azure Infrastructure Solutions
 
Infrastructure as a service and code using Azure - DevOps practice
Infrastructure as a service and code using Azure  - DevOps practiceInfrastructure as a service and code using Azure  - DevOps practice
Infrastructure as a service and code using Azure - DevOps practice
 
Session 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian MalbeufSession 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian Malbeuf
 
Designing azure compute and storage infrastructure
Designing azure compute and storage infrastructureDesigning azure compute and storage infrastructure
Designing azure compute and storage infrastructure
 
Day 3 - DevOps Culture - Continuous Integration & Continuous Deployment on th...
Day 3 - DevOps Culture - Continuous Integration & Continuous Deployment on th...Day 3 - DevOps Culture - Continuous Integration & Continuous Deployment on th...
Day 3 - DevOps Culture - Continuous Integration & Continuous Deployment on th...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Automating Your Azure Environment

  • 1. Automating Your Azure Environment Michael S. Collier Cloud Solution Architect, Microsoft Level: Intermediate
  • 2. Michael S. Collier Cloud Solution Architect Microsoft michael.collier@microsoft.com @MichaelCollier www.MichaelSCollier.com http://aka.ms/csablog
  • 4. Today’s Agenda 1. Why Automation in Azure? 2. Azure Management Library 3. Azure PowerShell a) Azure Service Management b) Azure Resource Manager 4. Azure Automation
  • 6. Why Automation? • Time to provision full environments – Compute, storage, etc. • Deployment to multiple geographies – Change only configuration / parameters
  • 7. Why Automation? #1 source of failed projects (IMO) Humans TERRIBLE at repetitive tasks
  • 8. A Few Options REST API • Service Management • Resource Manager
  • 9. A Few Options REST API • Service Management • Resource Manager Azure Management Library
  • 10. A Few Options REST API • Service Management • Resource Manager Azure Management Library PowerShell • Invoke REST • Service Management • Resource Manager
  • 11. A Few Options REST API • Service Management • Resource Manager Azure Management Library PowerShell • Invoke REST • Service Management • Resource Manager XPlat CLI • ??
  • 12. A Few Options REST API • Service Management • Resource Manager Azure Management Library PowerShell • Invoke REST • Service Management • Resource Manager XPlat CLI • ?? Azure Automation
  • 13. A Few Options REST API • Service Management • Resource Manager Azure Management Library PowerShell • Invoke REST • Service Management • Resource Manager XPlat CLI • ?? Azure Automation
  • 15. Azure Management Library • Consistent modern libraries over the Azure REST API – NET, Java, Python, Go, & Ruby
  • 17. Azure Management Library • Scenarios – Integration Testing – Custom provisioning of services (SaaS) – Dev/Test – Resource Governance • Almost anything you may want to automate
  • 18. Azure Management Library • Microsoft.WindowsAzure.* – Older RDFE version – Not recommended • Microsoft.Azure.* – Based on new Azure Resource Manager (ARM) – Recommended
  • 19. Azure Management Library • Get all or just the ones you need
  • 20. Authentication • Azure Active Directory • Create a service principal – Password (PowerShell or CLI) – Certificate (PowerShell) • Assign necessary ROLE to the service principal
  • 21. Create the Service Principal Switch-AzureMode AzureResourceManager Select-AzureSubscription -SubscriptionName “My MSDN Azure” $appName = "VSLiveNYC2015" $appHomePage = "http://localhost" $appUri = "http://localhost" $pwd = "test!123" # Create a new Azure AD application $azureAdApp = New-AzureADApplication -DisplayName $appName -HomePage $appHomePage -IdentifierUris $appUri -Password $pwd -Verbose # Create a service principal New-AzureADServicePrincipal -ApplicationId $azureAdApp.ApplicationId # Assign a role to the service principal New-AzureRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $azureAdApp.ApplicationId # Get the subscription for the role assignment $subscription = Get-AzureSubscription | where { $_.IsCurrent } # Create a new credential object to contain the credentials $creds = Get-Credential -UserName $azureAdApp.ApplicationId -Message "enter your creds" Add-AzureAccount -Credential $creds -ServicePrincipal -Tenant $subscription.TenantId Get this at http://aka.ms/uognfb
  • 22. Get the Authentication Token private const string SubscriptionId = “[YOUR_AZURE_SUBSCRIPTION_ID]"; private const string TenantId = “[YOUR_AZURE_AD_TENANT_ID]"; private const string ApplicationId = “[YOUR_NEWLY_REGISTERED_APP_id]"; private const string ApplicationPwd = "test!123"; public static string GetAToken() { var authenticationContext = new AuthenticationContext(string.Format("https://login.windows.net/{0}", TenantId)); var credential = new ClientCredential(clientId: ApplicationId, clientSecret: ApplicationPwd); var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential); if (result == null) { throw new InvalidOperationException("Failed to obtain the JWT token"); } string token = result.AccessToken; return token; } Get this at http://aka.ms/uognfb
  • 24. Demo Recap 1. Create a Service Principal in Azure AD 2. Get the JWT authentication token 3. Create a credential object with token and subscription 4. Create a resource client 5. Execute actions against the client
  • 25. PowerShell Cmdlets • Get the goods http://azure.microsoft.com/en-us/downloads/ https://github.com/Azure/azure-powershell/releases 
  • 26. PowerShell • Use cmdlets and/or REST APIs • Ability to script complex environments – Template with an XML parameters file – PowerShell learning curve – Your responsibility to handle errors & ensure consistency • Consistent Deployments – Build server or developer machine
  • 27. Authentication Options • Interactive – Azure AD PS C:> Add-AzureAccount C:Users<user>AppDataRoamingWindows Azure Powershell
  • 28. Authentication Options • Interactive – Azure AD PS C:> Add-AzureAccount VERBOSE: Account "michael.collier@live.com" has been added. VERBOSE: Subscription "MSFT Azure Internal - Collier" is selected as the default subscription. VERBOSE: To view all the subscriptions, please use Get-AzureSubscription. VERBOSE: To switch to a different subscription, please use Select-AzureSubscription. Id Type Subscriptions Tenants -- ---- ------------- ------- michael.collier@live.com User 0bbbc191-0023-aaaa-yyyy-xxxxxxxxxxxx 9b6b07ee-3eb1-aaaa-yyyy-xxxxxxxxxxxx 278b93db-29ab-aaaa-yyyy-xxxxxxxxxxxx 715f4ed0-544a-aaaa-yyyy-xxxxxxxxxxxx 3acf171d-3d34-aaaa-yyyy-xxxxxxxxxxxx 72f988bf-86f1-aaaa-yyyy-xxxxxxxxxxxx c68d7703-d6ed-aaaa-yyyy-xxxxxxxxxxxx 20acfbf0-4318-aaaa-yyyy-xxxxxxxxxxxx 57c8cb4e-3ce2-aaaa-yyyy-xxxxxxxxxxxx a28aed54-1dc8-aaaa-yyyy-xxxxxxxxxxxx b5fb8dfb-3e0b-aaaa-yyyy-xxxxxxxxxxxx 362755da-bfb2-aaaa-yyyy-xxxxxxxxxxxx 9a94b816-e790-aaaa-yyyy-xxxxxxxxxxxx 7805bdb6-17da-aaaa-yyyy-xxxxxxxxxxxx cd978409-0ac9-aaaa-yyyy-xxxxxxxxxxxx C:Users<user>AppDataRoamingWindows Azure Powershell
  • 29. Authentication Options • Programmatic – Management certificate – New –credentials option $userName = "<your work/school account user name>" $securePassword = ConvertTo-SecureString -String "<your work/school account password>" - AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword) Add-AzureAccount -Credential $cred
  • 30. Demo Create a VM with Custom Script Extension Deploy a Cloud Service
  • 31. Demo Recap 1. Authenticate PowerShell with Azure 2. Upload to blob storage a .ps1 script to format drives 3. Provision new Azure VM via PowerShell. a) Custom script extension to format data disks 4. Create Cloud Service (web role) project 5. PowerShell script to upload and deploy
  • 32. Azure Resource Manager What is Azure Resource Manager? Unit of Management • Lifecycle • Identity • Grouping One Resource -> One Resource Group
  • 33. ARM Benefits Desired-state deployment Faster deployment Role-based access control (RBAC) Resource-provider model Orchestration Resource configuration SQL - A Website Virtual Machines SQL-A Website [SQL CONFIG] VM (2x) DEPENDS ON SQLDEPENDS ON SQL SQLCONFIG Image source - http://channel9.msdn.com/Events/Build/2014/2-607
  • 35. ARM Functions ARM Templates supports small set of built-in functions parameters, variables reference, resourceGroup, resourceId base64, concat, padLeft, padLeft, replace, toLower, toUpper deployment, provider, subscription listKeys Not supported User-defined functions Control constructs – if, while, etc.
  • 36. Loops and Nested Templates Loops Provide basic copy capability Useful in cloning resource configuration For example, deploying multiple VMs Nested Templates One template can invoke another Simplifies creation of sophisticated templates Supports parameters Supports output variables
  • 37. ARM Deployment Logs Logs Provider Resource group Resource Availability Kept for 15 days Default is last hour (PowerShell) Filter by Status e.g., Failed PowerShell Get-AzureResourceProviderLog Get-AzureResourceGroupLog Get-AzureResourceLog
  • 38. Demo Create a new Azure Web App + SQL DB
  • 39. Demo Recap 1. Get latest Azure SDK for Visual Studio 2. Create new ‘Azure Resource Group’ project 3. Add Web App + SQL template 4. Provide parameters 5. Deploy via PowerShell
  • 40. What is Azure Automation? • IT process automation solution for Azure – Creation, monitoring, deployment, & maintenance – Runbooks & Assets – Leverage existing PowerShell scripts
  • 41. Runbook Types • PowerShell Workflow – Windows Workflow Foundation • Checkpoint, suspend, & resume – Parallel or serial execution – Compilation (time increases as complexity increases) • PowerShell (native) – No checkpoint, suspend, or resume – Serial execution only – No compile step! Fast!
  • 43. Demo Recap 1. Create Azure Automation account a) Create an AAD user for Azure Automation b) Create an Azure Connection Asset 2. Create Runbook to Stop VMs 1. Connect to Azure subscription 2. Iterate over all services and VMs 3. Test Runbook 4. Publish Runbook 5. Link Runbook to a Schedule
  • 44. Choices . . . When to Use
  • 45. Resources • Azure Resource Manager Preview SDKs – https://azure.microsoft.com/en-us/blog/azure-resource-manager-preview-sdks/ • Authenticating a service principal with Azure Resource Manager – https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate- service-principal/ • Keith Mayer’s blog posts on Azure Automation – http://blogs.technet.com/b/keithmayer/archive/2014/04/04/step-by-step-getting-started- with-windows-azure-automation.aspx
  • 47. Thank You! Michael S. Collier @MichaelCollier | www.michaelscollier.com michaelscollier@gmail.com | michael.collier@microsoft.com

Notes de l'éditeur

  1. Consistent modern libraries over Azure REST API Largely auto-generated (AutoRest; Swagger) .NET Node.js Java
  2. MAML provides the basis for the PowerShell cmdlets (old code slowly being replaced)
  3. https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#concepts
  4. https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/
  5. Authenticate with Azure AD Browse VMs Create a VM / Web Site DocumentDB
  6. http://azure.microsoft.com/en-us/downloads/ https://github.com/Azure/azure-powershell/releases
  7. When working with the management APIs, PowerShell can be valuable.
  8. C:\Users\Michael\AppData\Roaming\Windows Azure Powershell
  9. C:\Users\Michael\AppData\Roaming\Windows Azure Powershell
  10. Alternative – certificate (manual or PublishSettings)
  11. Resource - an Azure entity such as a VM, WebSite, Storage Account, SQL Database Resource Group Collection of Azure resources Every Resource must exist in one, and only one, Resource Group Unit of Management Lifecyle - deployment, update, delete, obtain status Grouping - Billing
  12. Repeatedly provision resources
  13. https://management.azure.com/subscriptions/{{subscriptionId}}/resourcegroups/{{resource-group}}/providers/Microsoft.Sql/servers/{{server}}/databases/{{database}}?api-version={{apiVersion}}
  14. https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/