Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Your Azure Infrastructure as Code With .Net Core - Global Azure 2021

Build Your Azure Infrastructure as Code With .Net Core - Global Azure 2021

Hossam Barakat

April 15, 2021
Tweet

More Decks by Hossam Barakat

Other Decks in Technology

Transcript

  1. Build Your Azure Infrastructure as Code With .NET Core Hossam

    Barakat Technical Lead at Willow @hossambarakat_ | www.hossambarakat.net
  2. @hossambarakat_ • Azure Resource Manager • Terraform • Bicep •

    AWS CloudFormation • Google Deployment Manager • … Declarative Infrastructure as Code tools
  3. @hossambarakat_ • Pulumi is an open source infrastructure as code

    tool the lets you use real languages – C#, TypeScript, Go,… – to provision and manage cloud resources. What is Pulumi?
  4. @hossambarakat_ • Control flow with loops and if conditions •

    Abstraction with functions, classes, packages,… • Code sharing with package management (Nuget, npm,…) • Authoring with favourite IDEs, refactoring, code completion, static type checking • Testing with existing frameworks and tools Benefits
  5. @hossambarakat_ Terraform vs Pulumi var resourceGroup = new ResourceGroup("pulumi-resources", new

    ResourceGroupArgs { Location = " Australia East" }); ); var environments = new string[]{"dev", "uat", "prod"}; foreach (var environment in environments) { var storageAccount = new StorageAccount( $"storage{environment}", new StorageAccountArgs { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Sku = new SkuArgs{ Name = SkuName.Standard_LRS }, AccessTier = AccessTier.Hot }); } resource "azurerm_resource_group" "rg" { name = "terraform-resources" location = ”Australia East" } variable "environments" { description = "storage account regions" type = list(string) default = ["dev", "uat", "prod"] } resource "azurerm_storage_account" "sa" { name = "iacpulumi${var.environments[count.index]}" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location account_tier = "Standard" account_replication_type = "LRS" count = length(var.environments) }
  6. @hossambarakat_ Projects & Stacks web-app (Pulumi.yaml) Project $ pulumi new

    Stacks $ pulumi stack init stackName Pulumi.<stack-name>.yaml Pulumi.yaml
  7. @hossambarakat_ Configurations $ pulumi config set dbPassword S3cr37 config: serverless-app:dbPassword:

    S3cr37 Pulumi.<stack-name>.yaml var config = new Pulumi.Config(); var password = config.Require("dbPassword"); Pulumi.cs
  8. @hossambarakat_ Secrets $ pulumi config set --secret dbPassword S3cr37 var

    config = new Pulumi.Config(); var password = config.Require("dbPassword"); Pulumi.cs Pulumi.<stack-name>.yaml config: serverless-app:dbPassword: secure: AAABAELDrCQE+rQbzTxN43iAD6iGDXTYQ90AzpILkfEY3uwtc+g=
  9. @hossambarakat_ How Pulumi Works State CLI and Engine AWS Azure

    Kubernetes Providers Code Plan Apply new Resource()