Test Kitchen Setup with Azure

Setup Test Kitchen on Azure

  • note: Refer here for Test Kitchen intro and setup in AWS

Azure Driver

  • Prerequisites:
    • SSH Client: Git or Putty
    • IDE: Visual Studio Code with Chef Extension
    • ChefDk installed
    • Azure CLI installed
  • Generate cookbook on the workstation
    chef generate cookbook nginx_cookbook
    cd nginx_cookbook
    
  • Azure Preparation
    • Kitchen-azurerm driver is used. For more info refer here
    • The following details are to be fetched
      • Subscription ID: available from the Azure portal
      • Client ID: this will be the Application Id from the application in step 2.
      • Client Secret/Password: this will be the password you supplied in the command in step 2.
      • Tenant ID: use the command detailed in "Manually provide credentials through Azure CLI" step 1 to get the TenantId.
    • Execute the following command and note the subscription id and tenant id
    # login into azure
    az login
    az account show --query "{subscriptionId:id, tenantId:tenantId}"
    
    • Create the Service Principal for use
    az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"
    
    • Your appId, password, sp_name, and tenant are returned. Make a note of the appId and password
    • appId is ClientID and password is client secret
    • Create a file @ ~/.azure/credentials with following info
    [12345678-YOUR-SUBSCRIPTION-ID-HERE-123456789abc]
    client_id = "ClientID"
    client_secret = "ClientSecret"
    tenant_id = "tenantid"
    
    • change your .kitchen.yml to
    ---
    driver:
        name: azurerm
        subscription_id: "yoursubscriptionid"
        location: "Central Us"
        machine_size: 'Standard_B1s'
    
    provisioner:
        name: chef_zero
        # You may wish to disable always updating cookbooks in CI or other testing environments.
        # For example:
        #   always_update_cookbooks: <%= !ENV['CI'] %>
        always_update_cookbooks: true
    
    verifier:
        name: inspec
    
    platforms:
    - name: ubuntu-14.04
      driver:
        image_urn: Canonical:UbuntuServer:14.04.4-LTS:latest
        vm_name: trusty-vm
        vm_tags:
            ostype: linux
            distro: ubuntu
    
    
    suites:
    - name: default
        run_list:
        - recipe[nginx_cookbook::default]
        verifier:
        inspec_tests:
            - test/integration/default
        attributes:
    
    • Execute the Command
    kitchen converge
    kitchen login
    
    • You can verify & once you finish the work destroy.
    • Note: The default user name is azure & password is P2ssw0rd

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner