-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from thomasyip-msft/terraform
Terraform sample
- Loading branch information
Showing
7 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
page_type: sample | ||
languages: | ||
- terraform` | ||
products: | ||
- azure-kubernetes-service | ||
- azure-marketplace | ||
--- | ||
|
||
# Azure Kubernetes Service (AKS) Terraform sample | ||
|
||
This sample provides a Terraform configuration to deploy kubernetes application azure-vote on Azure Kubernetes Service (AKS). | ||
|
||
## Prerequisites | ||
|
||
- [Terraform](https://www.terraform.io/downloads.html) | ||
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) | ||
|
||
|
||
|
||
## Prepare the environment | ||
|
||
- Initialize Terraform in the current directory by running the following command: | ||
|
||
```bash | ||
terraform init | ||
``` | ||
|
||
- There are 2 example tfvars files in the current directory. You can use them to deploy the application with different configurations. | ||
|
||
- `azure-vote-without-config.tfvars` - Deploy the application with default configuration for azure-vote. | ||
- `azure-vote-with-config.tfvars` - Deploy/update the application with custom configuration for azure-vote. | ||
|
||
- Before you test run the sample tfvars files, you need to update the followings in the tfvars files: | ||
|
||
- `cluster_name` - The name of the AKS cluster. | ||
- `resource_group_name` - The name of the resource group where AKS cluster is located. | ||
- `subscription_id` - The subscription ID where AKS cluster is located. | ||
|
||
|
||
## Deploy the application | ||
|
||
- Deploy the application with default configuration for azure-vote. | ||
|
||
```bash | ||
terraform apply -var-file="azure-vote-without-config.tfvars" | ||
``` | ||
|
||
|
||
- Deploy/update the application with custom configuration for azure-vote. | ||
|
||
```bash | ||
terraform apply -var-file="azure-vote-with-config.tfvars" | ||
``` | ||
|
||
## Clean up the resources | ||
|
||
- To clean up the resources, run the following command to delete the azure-vote application from your AKS cluster: | ||
|
||
```bash | ||
terraform destroy -var-file="azure-vote-without-config.tfvars" | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
terraform destroy -var-file="azure-vote-with-config.tfvars" | ||
``` | ||
|
||
|
||
## Limitations | ||
|
||
- Once you have deployed the application with configurations settings, you cannot use terraform to delete 1 of the existing configurations. You can instead use Azure portal (under Kubernetes service ->Extensions + applications) to remove the particular configuration settings. | ||
|
||
![alt text](image/deleteconfigurationsetting.png) |
13 changes: 13 additions & 0 deletions
13
samples/terraform/k8s-extension-install/azure-vote-with-config.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
subscription_id = "" | ||
resource_group_name = "" | ||
cluster_name = "" | ||
extension_type = "commercialMarketplaceServices.AzureVote" | ||
extension_resource_name = "azure-vote" | ||
publisher = "microsoft_commercial_marketplace_services" | ||
product-id = "azure-vote-final-1" | ||
plan-name = "azure-vote-paid" | ||
extension_configuration_settings = { | ||
title = "Azure Vote App Example" | ||
value1 = "BMW" | ||
value2 = "Mercedes" | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/terraform/k8s-extension-install/azure-vote-without-config.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
subscription_id = "" | ||
resource_group_name = "" | ||
cluster_name = "" | ||
extension_type = "commercialMarketplaceServices.AzureVote" | ||
extension_resource_name = "azure-vote" | ||
publisher = "microsoft_commercial_marketplace_services" | ||
product-id = "azure-vote-final-1" | ||
plan-name = "azure-vote-paid" | ||
extension_configuration_settings = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource "azurerm_kubernetes_cluster_extension" "k8sxtension" { | ||
name = var.extension_resource_name | ||
cluster_id = "/subscriptions/${var.subscription_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.ContainerService/managedClusters/${var.cluster_name}" | ||
extension_type = var.extension_type | ||
configuration_settings = var.extension_configuration_settings == null ? {} : var.extension_configuration_settings | ||
plan { | ||
name = var.plan-name | ||
product = var.product-id | ||
publisher = var.publisher | ||
} | ||
} |
Binary file added
BIN
+55.3 KB
samples/terraform/k8s-extension-install/image/deleteconfigurationsetting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~>3.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
variable "cluster_name" { | ||
type = string | ||
description = "The name of the Kubernetes cluster." | ||
} | ||
|
||
variable "resource_group_name" { | ||
type = string | ||
description = "The name of the resource group." | ||
} | ||
|
||
variable "subscription_id" { | ||
type = string | ||
description = "The subscription ID." | ||
|
||
} | ||
|
||
variable "extension_type" { | ||
type = string | ||
description = "The type of the extension." | ||
} | ||
|
||
variable "extension_resource_name" { | ||
type = string | ||
description = "The name of the extension resource." | ||
} | ||
|
||
variable "publisher" { | ||
type = string | ||
description = "The publisher of the extension." | ||
} | ||
|
||
variable "product-id" { | ||
type = string | ||
description = "The product ID of the extension." | ||
} | ||
|
||
variable "plan-name" { | ||
type = string | ||
description = "The plan name of the extension." | ||
} | ||
|
||
variable "extension_configuration_settings" { | ||
type = map(string) | ||
nullable = true | ||
description = "The configuration settings for the extension." | ||
} | ||
|