From 22350913fd23da06bbd7cfe03172d86128b6f90f Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Tue, 30 Aug 2022 10:54:01 -0700 Subject: [PATCH] Moving cosmosdb quickstart code to samples repo --- README.md | 48 +++++++++---------- .../aci.tf | 33 +++++++++++++ .../main.tf | 32 +++++++++++++ .../outputs.tf | 11 +++++ .../providers.tf | 18 +++++++ .../readme.md | 21 ++++++++ .../variables.tf | 9 ++++ quickstart/README.md | 5 +- 8 files changed, 152 insertions(+), 25 deletions(-) create mode 100644 quickstart/101-cosmos-db-azure-container-instance/aci.tf create mode 100644 quickstart/101-cosmos-db-azure-container-instance/main.tf create mode 100644 quickstart/101-cosmos-db-azure-container-instance/outputs.tf create mode 100644 quickstart/101-cosmos-db-azure-container-instance/providers.tf create mode 100644 quickstart/101-cosmos-db-azure-container-instance/readme.md create mode 100644 quickstart/101-cosmos-db-azure-container-instance/variables.tf diff --git a/README.md b/README.md index 8c8c70c3..aa4fba14 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/aci.tf b/quickstart/101-cosmos-db-azure-container-instance/aci.tf new file mode 100644 index 00000000..2e33f631 --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/aci.tf @@ -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" + } + } +} \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/main.tf b/quickstart/101-cosmos-db-azure-container-instance/main.tf new file mode 100644 index 00000000..852d38bc --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/main.tf @@ -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 + } +} \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/outputs.tf b/quickstart/101-cosmos-db-azure-container-instance/outputs.tf new file mode 100644 index 00000000..3e5ec703 --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/outputs.tf @@ -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 +} \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/providers.tf b/quickstart/101-cosmos-db-azure-container-instance/providers.tf new file mode 100644 index 00000000..5343d826 --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/providers.tf @@ -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 {} +} \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/readme.md b/quickstart/101-cosmos-db-azure-container-instance/readme.md new file mode 100644 index 00000000..48383ff8 --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/readme.md @@ -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). \ No newline at end of file diff --git a/quickstart/101-cosmos-db-azure-container-instance/variables.tf b/quickstart/101-cosmos-db-azure-container-instance/variables.tf new file mode 100644 index 00000000..e8396125 --- /dev/null +++ b/quickstart/101-cosmos-db-azure-container-instance/variables.tf @@ -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." +} \ No newline at end of file diff --git a/quickstart/README.md b/quickstart/README.md index e94f3ca5..e9e96a1b 100644 --- a/quickstart/README.md +++ b/quickstart/README.md @@ -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/) \ No newline at end of file