Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Story 95456 #227

Merged
merged 5 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions quickstart/201-k8s-cluster-with-tf-and-aks/azure-vote.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-back
template:
metadata:
labels:
app: azure-vote-back
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: azure-vote-back
image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 6379
name: redis
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-back
spec:
ports:
- port: 6379
selector:
app: azure-vote-back
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-front
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-front
template:
metadata:
labels:
app: azure-vote-front
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: azure-vote-front
image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
env:
- name: REDIS
value: "azure-vote-back"
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-front
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: azure-vote-front
30 changes: 0 additions & 30 deletions quickstart/201-k8s-cluster-with-tf-and-aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,6 @@ resource "azurerm_resource_group" "rg" {
name = random_pet.rg_name.id
}

data "azurerm_client_config" "current" {}

locals {
current_user_id = coalesce(var.msi_id, data.azurerm_client_config.current.object_id)
}

resource "random_pet" "azurerm_log_analytics_workspace_name" {
prefix = "ws"
}

resource "azurerm_log_analytics_workspace" "test" {
location = var.log_analytics_workspace_location
name = random_pet.azurerm_log_analytics_workspace_name.id
resource_group_name = azurerm_resource_group.rg.name
sku = var.log_analytics_workspace_sku
}

resource "azurerm_log_analytics_solution" "test" {
location = azurerm_log_analytics_workspace.test.location
resource_group_name = azurerm_resource_group.rg.name
solution_name = "ContainerInsights"
workspace_name = azurerm_log_analytics_workspace.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id

plan {
product = "OMSGallery/ContainerInsights"
publisher = "Microsoft"
}
}

resource "random_pet" "azurerm_kubernetes_cluster_name" {
prefix = "cluster"
}
Expand Down
4 changes: 0 additions & 4 deletions quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ output "kubernetes_cluster_name" {
value = azurerm_kubernetes_cluster.k8s.name
}

output "log_analytics_workspace_name" {
value = azurerm_log_analytics_workspace.test.name
}

output "client_certificate" {
value = azurerm_kubernetes_cluster.k8s.kube_config[0].client_certificate
sensitive = true
Expand Down
4 changes: 0 additions & 4 deletions quickstart/201-k8s-cluster-with-tf-and-aks/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ This template provisions an [AKS / Azure Kubernetes service (also known as a Man
- [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)
- [azurerm_client_config](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config)
- [azurerm_log_analytics_workspace](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace)
- [azurerm_log_analytics_solution](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_solution)
- [azurerm_kubernetes_cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster)
- [azuread_application](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/application)
- [azuread_service_principal](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/service_principal)
Expand All @@ -25,8 +23,6 @@ This template provisions an [AKS / Azure Kubernetes service (also known as a Man
| `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 |
| `node_count` | Initial number of nodes which should exist in this Node Pool. Value must be between 1 and 1000. | 3 |
| `log_analytics_workspace_location` | Location of the Log Analytics workspace. | eastus |
| `log_analytics_workspace_sku` | SKU of the Log Analytics workspace. The SKU of the log analytics workspace. Choose from: Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, PerGB2018 | PerGB2018 |

## Example

Expand Down
14 changes: 10 additions & 4 deletions quickstart/201-k8s-cluster-with-tf-and-aks/sp.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Create Azure AD App Registration
data "azurerm_client_config" "current" {}

locals {
current_user_id = coalesce(var.msi_id, data.azurerm_client_config.current.object_id)
}

# Create Azure AD app registration.
resource "azuread_application" "app" {
display_name = "my-app"
owners = [local.current_user_id]
}

# Create Service Principal
# Create service principal.
resource "azuread_service_principal" "app" {
application_id = azuread_application.app.application_id
app_role_assignment_required = true
owners = [local.current_user_id]
}

# Create Service Principal password
# Create service principal password.
resource "azuread_service_principal_password" "app" {
service_principal_id = azuread_service_principal.app.id
}
Expand All @@ -25,7 +31,7 @@ resource "time_sleep" "wait_30_seconds" {
depends_on = [azuread_service_principal_password.app]
}

# Output the Service Principal and password
# Output the service principal and password.
output "sp" {
value = azuread_service_principal.app.id
sensitive = true
Expand Down
21 changes: 0 additions & 21 deletions quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ variable "node_count" {
default = 3
}

# For available Log Analytics regions, refer to:
# https://azure.microsoft.com/global-infrastructure/services/?products=monitor
variable "log_analytics_workspace_location" {
type = string
default = "eastus"
description = "Location of the Log Analytics workspace."
}

# For Log Analytics pricing, refer to:
# https://azure.microsoft.com/pricing/details/monitor
variable "log_analytics_workspace_sku" {
type = string
description = "The SKU of the Log Analytics workspace. Choose from: Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, PerGB2018"
default = "PerGB2018"

validation {
condition = contains(["Free", "PerNode", "Premium", "Standard", "Standalone", "Unlimited", "CapacityReservation", "PerGB2018"], var.log_analytics_workspace_sku)
error_message = "The Log Analytics workspace SKU must be one of the following: Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, PerGB2018"
}
}

variable "msi_id" {
TomArcherMsft marked this conversation as resolved.
Show resolved Hide resolved
type = string
description = "The Managed Service Identity ID used to create the service principal. If this value is null (the default), the AzureRM provider configuration Object ID is used.."
Expand Down