Skip to content

Commit

Permalink
Merge pull request #47 from thomasyip-msft/terraform
Browse files Browse the repository at this point in the history
Terraform sample
  • Loading branch information
RamyasreeChakka authored Dec 10, 2024
2 parents a97acc5 + 31bccda commit 1c6fc7e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
75 changes: 75 additions & 0 deletions samples/terraform/k8s-extension-install/README.md
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)
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"
}
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
11 changes: 11 additions & 0 deletions samples/terraform/k8s-extension-install/extension.tf
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions samples/terraform/k8s-extension-install/providers.tf
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 {}
}
47 changes: 47 additions & 0 deletions samples/terraform/k8s-extension-install/variables.tf
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."
}

0 comments on commit 1c6fc7e

Please sign in to comment.