Satyam Pandey
Satyam Pandey

Reputation: 743

AKS integration with ACR

trying to create ACR and integrate the same with existing AKS cluster

below is the resource block where will be doing role assignment {User Assigned Managed Identity} to aks nodepool and trying datablock to fetch existing aks details

#Create Resource Group 
resource "azurerm_resource_group" "acr_rg" {
  location = var.location
  name     = "${var.global-prefix}-${var.repo-id}-rg"
}

#Create ACR Registry for Powerme
resource "azurerm_container_registry" "acr" {
  name                = var.repo-id
  resource_group_name = azurerm_resource_group.acr_rg.name
  location            = azurerm_resource_group.acr_rg.location
  sku                 = "Premium"
  admin_enabled       = true
}

#Featching AKS details for Integration with ACR
data "azurerm_kubernetes_cluster" "aks_cluster" {
  resource_group_name = var.aks_rg
  name                = var.k8s_cluster
}

#Role assignment of vmss to acr
resource "azurerm_role_assignment" "acrpull_role" {
  scope                = azurerm_container_registry.acr.id
  role_definition_name = "AcrPull"
  principal_id         = data.azurerm_kubernetes_cluster.aks_cluster.kubelet_identity[0].object_id
}

error

$ terraform plan
╷
│ Error: Error: Managed Kubernetes Cluster "mycluster" was not found in Resource Group "myresource"
│ 
│   with data.azurerm_kubernetes_cluster.aks_cluster,
│   on acr.tf line 17, in data "azurerm_kubernetes_cluster" "aks_cluster":
│   17: data "azurerm_kubernetes_cluster" "aks_cluster" {
╵

Upvotes: 0

Views: 777

Answers (2)

Denyroprez
Denyroprez

Reputation: 1

1.Create a new AKS cluster with ACR integration

Create an ACR

Set this variable to the name of your ACR. The name must be globally unique.

MYACR=myContainerRegistry

az acr create -n $MYACR -g myContainerRegistryResourceGroup --sku basic

I attach a link to this message to follow the tutorial

https://learn.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli

Upvotes: 0

Ansuman Bal
Ansuman Bal

Reputation: 11401

If you have multiple subscriptions access, Please ensure you are setting the subscription that has the aks cluster and the resource group by using the below command:

az account set --subscription "your subscription you want to use"

After the Subscription is set , You will be successfully able to get the AKS cluster and resource group using the same code .

Upvotes: 2

Related Questions