Skip to content

Commit f1a9a46

Browse files
puicchanhhunter-ms
andauthored
[READY FOR REVIEW] Add TR support (#3533)
* Add TF support * Add TOC * Minor edit * Add install TF instruction * Apply suggestions from code review Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com> * Address feedback add extra instruction. * Add more details for remote state * Update index and TOC * Fixed formatting issues * Add links to templates and addition TF edits * Apply suggestions from code review Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com> * update to azd pipeline config for TF * more clarification for azd pipeline config. * Readd node.js template for TF * Fixed wrong link for TF * Fixed broken link for TF * minor fix * Add node (TF) to list of template * Fixed broken link Co-authored-by: puicchan <puicchan> Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
1 parent f6a2db7 commit f1a9a46

File tree

4 files changed

+117
-12
lines changed

4 files changed

+117
-12
lines changed

articles/azure-developer-cli/TOC.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
href: overview.md
66
- name: Get started
77
href: get-started.md
8+
- name: Use Terraform as IaC Provider
9+
href: use-terraform-for-azd.md
810
- name: Run and debug
911
href: debug.md
1012
- name: Configure deployment pipeline

articles/azure-developer-cli/index.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ summary: |
77
metadata:
88
title: Azure Developer CLI (azd) Preview
99
description: Get started developing Azure apps using Azure Developer CLI (azd).
10-
author: puicchan
11-
ms.author: puichan
10+
author: hhunter-ms
11+
ms.author: hannahhunter
1212
ms.date: 07/11/2022
1313
ms.topic: landing-page
1414
ms.collection: collection
@@ -30,6 +30,8 @@ landingContent:
3030
linkLists:
3131
- linkListType: tutorial
3232
links:
33+
- text: Use Terraform as IaC Provider
34+
url: use-terraform-for-azd.md
3335
- text: Run and debug
3436
url: debug.md
3537
- text: Configure deployment pipeline

articles/azure-developer-cli/overview.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,29 @@ This list is grouped by supported language. Each repository contains a complete
3535

3636
### [Node.js](#tab/nodejs)
3737

38-
| Template | App host | Database |
38+
| Template | App host | Tech stack |
3939
| ----------- | ----------| ----------- |
40-
| [ToDo NodeJs Mongo](https://github.com/azure-samples/todo-nodejs-mongo) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction) |
41-
| [ToDo NodeJs Mongo ACA](https://github.com/azure-samples/todo-nodejs-mongo-aca) | [Azure Container Apps](/azure/container-apps/overview) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction) |
42-
| [ToDo NodeJs Mongo SWA + Functions](https://github.com/azure-samples/todo-nodejs-mongo-swa-func) | [Azure Static Web Apps](/azure/static-web-apps/), [Azure Functions](/azure/azure-functions/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction) |
40+
| [ToDo NodeJs Mongo](https://github.com/azure-samples/todo-nodejs-mongo) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep |
41+
| [ToDo NodeJs Mongo (Terraform)](https://github.com/azure-samples/todo-nodejs-mongo-terraform) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Terraform |
42+
| [ToDo NodeJs Mongo ACA](https://github.com/azure-samples/todo-nodejs-mongo-aca) | [Azure Container Apps](/azure/container-apps/overview) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep |
43+
| [ToDo NodeJs Mongo SWA + Functions](https://github.com/azure-samples/todo-nodejs-mongo-swa-func) | [Azure Static Web Apps](/azure/static-web-apps/), [Azure Functions](/azure/azure-functions/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep |
4344

4445

4546
### [Python](#tab/python)
4647

47-
| Template | App host | Database |
48+
| Template | App host | Tech stack |
4849
| ----------- | ----------| ----------- |
49-
| [ToDo Python Mongo](https://github.com/azure-samples/todo-python-mongo) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction) |
50-
| [ToDo Python Mongo ACA](https://github.com/azure-samples/todo-python-mongo-aca) | [Azure Container Apps](/azure/container-apps/overview) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction) |
51-
| [ToDo Python Mongo SWA + Functions](https://github.com/azure-samples/todo-python-mongo-swa-func) | [Azure Static Web Apps](/azure/static-web-apps/), [Azure Functions](/azure/azure-functions/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction)|
50+
| [ToDo Python Mongo](https://github.com/azure-samples/todo-python-mongo) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep |
51+
| [ToDo Python Mongo (Terraform)](https://github.com/Azure-Samples/todo-python-mongo-terraform) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Terraform |
52+
| [ToDo Python Mongo ACA](https://github.com/azure-samples/todo-python-mongo-aca) | [Azure Container Apps](/azure/container-apps/overview) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep |
53+
| [ToDo Python Mongo SWA + Functions](https://github.com/azure-samples/todo-python-mongo-swa-func) | [Azure Static Web Apps](/azure/static-web-apps/), [Azure Functions](/azure/azure-functions/) | [Azure Cosmos DB API for Mongo](/azure/cosmos-db/mongodb/mongodb-introduction), Bicep|
5254

5355
### [C#](#tab/csharp)
5456

55-
| Template | App host | Database |
57+
| Template | App host | Tech stack |
5658
| ----------- | ----------| ----------- |
57-
| [Todo C# Cosmos DB (SQL)](https://github.com/Azure-Samples/todo-csharp-cosmos-sql) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB SQL API](/learn/modules/intro-to-azure-cosmos-db-core-api/) |
59+
| [Todo C# Cosmos DB (SQL)](https://github.com/Azure-Samples/todo-csharp-cosmos-sql) | [Azure App Service](/azure/app-service/) | [Azure Cosmos DB SQL API](/learn/modules/intro-to-azure-cosmos-db-core-api/), Bicep |
60+
| [Todo C# Azure SQL Database](https://github.com/azure-samples/todo-csharp-sql) | [Azure App Service](/azure/app-service/) | [Azure SQL Database](/azure/azure-sql/database/sql-database-paas-overview), Bicep |
5861

5962
---
6063

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: Use Terraform as an infrastructure as code tool for Azure Developer CLI (azd) Preview
3+
description: How to use Terraform as an infrastructure as code tool for Azure Developer CLI (azd) Preview.
4+
author: hhunter-ms
5+
ms.author: hannahhunter
6+
ms.date: 09/14/2022
7+
ms.service: azure-dev-cli
8+
ms.topic: conceptual
9+
ms.custom: devx-track-azdevcli
10+
---
11+
12+
# Use Terraform as an infrastructure as code tool for Azure Developer CLI (azd) Preview
13+
14+
Azure Developer CLI (azd) Preview supports multiple infrastructure as code (IaC) providers, including:
15+
- [Bicep](/azure/azure-resource-manager/bicep/overview?tabs=bicep)
16+
- [Terraform](/azure/developer/terraform/overview)
17+
18+
By default, `azd` assumes Bicep as the IaC provider. Refer to the [Comparing Terraform and Bicep](/azure/developer/terraform/comparing-terraform-and-bicep?tabs=comparing-bicep-terraform-integration-features) article for help deciding which IaC provider is best for your project.
19+
20+
## Configure Terraform as the IaC provider
21+
22+
1. If you haven't already, [install and configure Terraform](/azure/developer/terraform/quickstart-configure?source=recommendations).
23+
1. Open the `azure.yaml` file found in the root of your project and make sure you have the following lines to override the default, which is Bicep:
24+
25+
```yaml
26+
infra:
27+
provider: terraform
28+
```
29+
30+
1. Add all your `.tf` files to the `infra` directory found in the root of your project.
31+
1. Run `azd up`.
32+
33+
> [!NOTE]
34+
> Check out these two azd templates with Terraform as IaC Provider: [Node.js and Terraform](https://github.com/Azure-Samples/todo-nodejs-mongo-terraform) and [Python and Terraform](https://github.com/Azure-Samples/todo-python-mongo-terraform).
35+
36+
## azd pipeline config for Terraform
37+
38+
Terraform stores state about your managed infrastructure and configuration. Because of this state file, you need to enable remote state **before** you run `azd pipeline config` to set up your deployment pipeline in GitHub.
39+
40+
By default, `azd` assumes the use of local state file. If you ran `azd up` before enabling remote state, you need to run `azd down` and switch to remote state file.
41+
42+
## Local vs remote state
43+
44+
Terraform uses persisted [state](https://www.terraform.io/language/state) data to keep track of the resources it manages.
45+
46+
Scenarios for enabling remote state:
47+
48+
- To allow shared access to the state data, and allow multiple people work together on that collection of infrastructure resources
49+
- To avoid exposing sensitive information included in state file
50+
- To decrease the chance of inadvertent deletion because of storing state locally
51+
52+
## Enable remote state
53+
54+
1. Make sure you [configure a remote state storage account](/azure/developer/terraform/store-state-in-azure-storage).
55+
1. Add a new file called `provider.conf.json` in the `infra` folder.
56+
57+
```json
58+
{
59+
"storage_account_name": "${RS_STORAGE_ACCOUNT}",
60+
"container_name": "${RS_CONTAINER_NAME}",
61+
"key": "azd/azdremotetest.tfstate",
62+
"resource_group_name": "${RS_RESOURCE_GROUP}"
63+
}
64+
```
65+
66+
1. Update `provider.tf` found in the `infra` folder to set the backend to be remote
67+
68+
```console
69+
# Configure the Azure Provider
70+
terraform {
71+
required_version = ">= 1.1.7, < 2.0.0"
72+
backend "azurerm" {
73+
}
74+
```
75+
76+
1. Run `azd env set <key> <value>` to add configuration in the `.env` file.
77+
For example:
78+
79+
```bash
80+
azd env set RS_STORAGE_ACCOUNT your_storage_account_name
81+
azd env set RS_CONTAINER_NAME your_terraform_container_name
82+
azd env set RS_RESOURCE_GROUP your_storage_account_resource_group
83+
```
84+
85+
1. Run the next `azd` command as per your usual workflow. When remote state is detected, `azd` initializes Terraform with the configured backend configuration.
86+
87+
1. To share the environment with teammates, make sure they run `azd env refresh -e <environmentName>` to refresh environment settings in the local system, and perform Step 4 to add configuration in the `.env` file.
88+
89+
## See also
90+
91+
- For more on remote state, see [store Terraform state in Azure Storage](/azure/developer/terraform/store-state-in-azure-storage).
92+
- Template: [Todo Application with Node.js and Terraform](https://github.com/Azure-Samples/todo-nodejs-mongo-terraform)
93+
- Template: [Todo Application with Python and Terraform](https://github.com/Azure-Samples/todo-python-mongo-terraform)
94+
95+
## Next steps
96+
97+
> [!div class="nextstepaction"]
98+
> [Azure Developer CLI FAQ](./faq.yml)

0 commit comments

Comments
 (0)