Moving cosmosdb quickstart code to samples repo

This commit is contained in:
Tom Archer 2022-08-30 10:54:01 -07:00
parent cb17e827ba
commit 22350913fd
8 changed files with 152 additions and 25 deletions

View File

@ -1,24 +1,24 @@
# Contributing
This project welcomes contributions and suggestions.
## Modules
Module summary
[Module contribution guide](./module/CONTRIBUTE.md)
## Providers
Provider summary
[Provider contribution guide](./provider/CONTRIBUTE.md)
# Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
# Contributing
This project welcomes contributions and suggestions.
## Modules
Module summary
[Module contribution guide](./module/CONTRIBUTE.md)
## Providers
Provider summary
[Provider contribution guide](./provider/CONTRIBUTE.md)
# Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

View File

@ -0,0 +1,33 @@
# This code sets two environment variables: COSMOS_DB_ENDPOINT and COSMOS_DB_MASTERKEY.
# These variables hold the location and key for accessing the database.
# The values for these variables are obtained from the database instance created in main.tf
# This process is known as interpolation.
# To learn more about Terraform interpolation, see https://www.terraform.io/language/v1.1.x/configuration-0-11/interpolation.
resource "azurerm_container_group" "vote_aci" {
name = "vote_aci"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
ip_address_type = "public"
dns_name_label = "vote_aci"
os_type = "linux"
container {
name = "vote_aci"
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.vote_cosmos_db.endpoint
"COSMOS_DB_MASTERKEY" = azurerm_cosmosdb_account.vote_cosmos_db.primary_master_key
"TITLE" = "Azure Voting App"
"VOTE1VALUE" = "Cats"
"VOTE2VALUE" = "Dogs"
}
}
}

View File

@ -0,0 +1,32 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = random_pet.rg_name.id
}
resource "random_integer" "ri" {
min = 10000
max = 99999
}
resource "azurerm_cosmosdb_account" "vote_cosmos_db" {
name = "tfex-cosmos-db-${random_integer.ri.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
consistency_policy {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 10
max_staleness_prefix = 200
}
geo_location {
location = azurerm_resource_group.rg.location
failover_priority = 0
}
}

View File

@ -0,0 +1,11 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "cosmosdb_account_name" {
value = azurerm_cosmosdb_account.vote_cosmos_db.name
}
output "dns" {
value = azurerm_container_group.vote_aci.fqdn
}

View File

@ -0,0 +1,18 @@
terraform {
required_version = ">=0.12"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}

View File

@ -0,0 +1,21 @@
# Azure Cosmos DB in an Azure Container Instance
This template shows how to use Terraform to deploy an Azure Cosmos DB to Azure Container Instances.
## Terraform resource types
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_integer](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer)
- [azurerm_cosmosdb_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_account)
## Variables
| Name | Description | Default |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
## Example
To see how to run this example, see [Deploy an Azure Cosmos DB to Azure Container Instances](https://docs.microsoft.com/azure/developer/terraform/deploy-azure-cosmos-db-to-azure-container-instances).

View File

@ -0,0 +1,9 @@
variable "resource_group_location" {
default = "eastus"
description = "Location of the resource group."
}
variable "resource_group_name_prefix" {
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}

View File

@ -17,6 +17,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
#### Beginner
- [Azure resource group](./101-resource-group)
- [Azure attestation provider](./101-attestation-provider)
- [Azure Cosmos DB in an Azure Container Instance](./101-cosmos-db-azure-container-instance)
- [Static Website hosted on Azure Storage](./101-storage-static-website)
- [Azure Web App hosting a Linux Container](./101-web-app-linux-container)
- [Azure Web App hosting a Java 8 App on Linux](./101-web-app-linux-java)
@ -25,6 +27,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
#### Intermediate
- [Azure Web App with ACR](./201-web-app-docker-acr/)
- [Azure Kubernetes Service with Kubernetes cluster](./201-k8s-cluster-with-tf-and-aks)
- [Azure Kubernetes Service with an Admin Dashboard](./201-aks-rbac-dashboard-admin/)
- [Azure Kubernetes Service with Log Analytics](./201-aks-log-analytics/)
- [Azure Kubernetes Service with Helm](./201-aks-helm/)
@ -52,4 +55,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
- [AppGateway fronted VM Scale Set](./201-vmss-appgw-waf/)
- [Azure Pipeline CI/CD for Terraform](./201-azure-pipelines-ci-cd/)
- [AKS with Windows node pools](./301-aks-windows-nodepool/)
- [Hub and Spoke VNet with VMs](./301-hub-spoke-network-3vm/)
- [Hub and Spoke VNet with VMs](./301-hub-spoke-network-3vm/)