Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
    • Data
Azure icon
Labs

Create a Cosmos DB Instance in Azure with Terraform

Hey, Gurus! Welcome to the Create a Cosmos DB Instance in Azure with Terraform lab. In this lab, we will cover these 4 objectives: 1. First, we will log into the Azure Portal, configure the Cloud Shell, and then download and run the lab setup script to setup our lab. 1. Second, we will import the resource group. 1. Third, we will create the configuration and deploy the Azure Cosmos DB instance. 1. And for the fourth objective, we will update our configuration with an application container instance that will use the database instance created in the previous step, with a simple database-driven application that we will test to verify if our deployment was successful.

Azure icon
Lab platform
Lab Info
Level
Advanced
Last updated
Sep 24, 2025
Duration
1h 0m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Set Up Cloud Shell and the Lab Environment

    In the Portal

    1. Go to the Azure Portal and log in using your lab credentials.
    2. Click the Cloud Shell icon next to the search bar in the Portal.
    3. Select Bash at the prompt.
    4. Click Show Advanced Settings.
    5. Set the Cloud Shell region to the same location as the resource group.
    6. Select the existing Resource group, and select Use Existing for the Storage account.
    7. In the File share section, choose Create new and enter "terraform".
    8. Click Attach storage.
    9. Download the lab_6_setup.sh script at https://raw.githubusercontent.com/ACloudGuru/advanced-terraform-with-azure/main/lab_cosmosdb_resources/lab_6_setup.sh.
    10. Add execute permissions to the script.
    11. Run the lab_6_setup.sh script.
  2. Challenge

    Import the Resource Group

    In the Cloud Shell

    1. In the Cloud Shell, review the cosmosDB.tf.
    2. Make note of the resource group name and label at the top and then close the file.
    3. Run the az group list command to get the subscription id.
    4. Import your resource group into Terraform using the resource group name, label, and subscription id.
    5. After the import, add the name and location of your resource group to the cosmosDB.tf file so it looks like the code below (fill in with your resource group and location):
      resource "azurerm_resource_group" "super-vote" {
          name     = "<RESOURCE_GROUP>"
          location = "<LOCATION>"
      }   
      
    6. Save the file.
  3. Challenge

    Deploy the Cosmos DB Instance

    In the Cloud Shell

    1. Open the cosmosDB.tf file.
    2. Define the Cosmos DB instance using the azurerm_cosmosdb_account resource with a label of super-vote.
    3. Create the DB instance using the following arguments and values:
      • name: "tfex-cosmos-db-${random_integer.ri.result}"
      • location: azurerm_resource_group.super-vote.location
      • resource_group_name: azurerm_resource_group.super-vote.name
      • offer_type: "Standard"
      • kind: "GlobalDocumentDB"
      • consistency_policy:
        • consistency_level: "BoundedStaleness"
        • max_interval_in_seconds: 10
        • max_staleness_prefix: 200
      • geo_location:
        • location: eastus
        • failover_priority: 0
    4. Save the changes.
    5. Apply the configuration.
  4. Challenge

    Update the Config, Deploy the Changes, and Test the Application

    In the Cloud Shell

    1. Open the cosmosDB.tf file.
    2. Define the Container Instance using the azurerm_container_group with a label of super-vote. Create the containuer using the following arguments and values:
      • name: "super-vote"
      • location: azurerm_resource_group.super-vote.location
      • resource_group_name: azurerm_resource_group.super-vote.name
      • ip_address_type: "public"
      • dns_name_label: "super-vote"
      • os_type: "linux"
      • container::
        • name: "super-vote"
        • image: "mcr.microsoft.com/azuredocs/azure-vote-front:cosmosdb"
        • cpu: "0.5"
        • memory: "1.5"
        • ports::
          • port: 80
          • protocol: "TCP"
      • secure_environment_variables::
        • COSMOS_DB_ENDPOINT: azurerm_cosmosdb_account.super-vote.endpoint
        • COSMOS_DB_MASTERKEY: azurerm_cosmosdb_account.super-vote.primary_master_key
        • TITLE: "Best Superhero!"
        • VOTE1VALUE: "Batman"
        • VOTE2VALUE: "Superman"
    3. Save the changes.
    4. Create a file called output.tf and paste the following:
      output "application_endpoint" {
        value = azurerm_container_group.super-vote.fqdn
      }
      
    5. Save the changes.
    6. Apply the configuration
    7. After the apply completes, copy the dns output for the application endpoint and go to your browser.
    8. Paste the link in your browser and go to the endpoint.
    9. Test the functionality of the application by voting to confirm and complete the lab.
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight