Skip to content

Commit 9eb5cb8

Browse files
authored
Merge pull request #227662 from TomArcherMsft/UserStory60501-aci-linuxcontainer-public-ip
User Story 60501: aci-linuxcontainer-public-ip
2 parents 55ab7b6 + 34b04cd commit 9eb5cb8

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

articles/container-instances/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
- name: Deploy a container instance - ARM template
2222
displayName: Resource Manager
2323
href: container-instances-quickstart-template.md
24+
- name: Deploy a container instance - Terraform
25+
href: container-instances-quickstart-terraform.md
2426
- name: Deploy a container instance - Docker CLI
2527
href: quickstart-docker-cli.md
2628
- name: Tutorials
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: 'Quickstart: Create an Azure Container Instance with a public IP address using Terraform'
3+
description: 'In this article, you create an Azure Container Instance with a public IP address using Terraform'
4+
ms.topic: quickstart
5+
ms.service: container-instances
6+
ms.date: 3/16/2023
7+
ms.custom: devx-track-terraform
8+
author: TomArcherMsft
9+
ms.author: tarcher
10+
---
11+
12+
# Quickstart: Create an Azure Container Instance with a public IP address using Terraform
13+
14+
Use Azure Container Instances to run serverless Docker containers in Azure with simplicity and speed. Deploy an application to a container instance on-demand when you don't need a full container orchestration platform like Azure Kubernetes Service. In this article, you use [Terraform](/azure/terraform) to deploy an isolated Docker container and make its web application available with a public IP address.
15+
16+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
17+
18+
In this article, you learn how to:
19+
20+
> [!div class="checklist"]
21+
> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/resource_group/pet)
22+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
23+
> * Create a random value for the container name using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
24+
> * Create an Azure container group using [azurerm_container_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group)
25+
26+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
27+
28+
## Prerequisites
29+
30+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
31+
32+
## Implement the Terraform code
33+
34+
> [!NOTE]
35+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-aci-linuxcontainer-public-ip). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-aci-linuxcontainer-public-ip/TestRecord.md).
36+
>
37+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
38+
39+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
40+
41+
1. Create a file named `main.tf` and insert the following code:
42+
43+
[!code-terraform[master](~/terraform_samples/quickstart/101-aci-linuxcontainer-public-ip/main.tf)]
44+
45+
1. Create a file named `outputs.tf` and insert the following code:
46+
47+
[!code-terraform[master](~/terraform_samples/quickstart/101-aci-linuxcontainer-public-ip/outputs.tf)]
48+
49+
1. Create a file named `providers.tf` and insert the following code:
50+
51+
[!code-terraform[master](~/terraform_samples/quickstart/101-aci-linuxcontainer-public-ip/providers.tf)]
52+
53+
1. Create a file named `variables.tf` and insert the following code:
54+
55+
[!code-terraform[master](~/terraform_samples/quickstart/101-aci-linuxcontainer-public-ip/variables.tf)]
56+
57+
## Initialize Terraform
58+
59+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
60+
61+
## Create a Terraform execution plan
62+
63+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
64+
65+
## Apply a Terraform execution plan
66+
67+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
68+
69+
## Verify the results
70+
71+
1. When you apply the execution plan, Terraform outputs the public IP address. To display the IP address again, run [terraform output](https://developer.hashicorp.com/terraform/cli/commands/output).
72+
73+
```console
74+
terraform output -raw container_ipv4_address
75+
```
76+
77+
1. Enter the sample's public IP address in your browser's address bar.
78+
79+
:::image type="content" source="./media/container-instances-quickstart-terraform/azure-container-instances-demo.png" alt-text="Screenshot of the Azure Container Instances sample page":::
80+
81+
## Clean up resources
82+
83+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
84+
85+
## Troubleshoot Terraform on Azure
86+
87+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
88+
89+
## Next steps
90+
91+
> [!div class="nextstepaction"]
92+
> [Tutorial: Create a container image for deployment to Azure Container Instances](./container-instances-tutorial-prepare-app.md)
30.9 KB
Loading

0 commit comments

Comments
 (0)