【发布时间】:2020-01-05 07:08:24
【问题描述】:
我正在尝试使用 Terraform 为 AKS 的服务主体创建 AKS、ACR 和角色分配。在这里,我想利用用 AKS 创建的 SP。
我指的是AKS Create cluster,它说在创建 aks 集群时会使用它创建一个 SP。
provider "azurerm" {
version = "~> 1.31.0"
client_id = ""
client_secret = ""
tenant_id = ""
subscription_id = ""
}
variable "tftranining_rg_name" {}
variable "tftranining_rg_location" {}
resource "azurerm_resource_group" "terraform_training_rg" {
name = "${var.tftranining_rg_name}"
location = "${var.tftranining_rg_location}"
}
resource "azurerm_kubernetes_cluster" "k8s_gateway" {
resource_group_name = "${var.tftranining_rg_name}"
name = "terraform_training_aks"
location = "${var.tftranining_rg_location}"
dns_prefix = "terraform_training_aks_dns"
agent_pool_profile {
name = "agentpool"
count = "1"
vm_size = "Standard_DS1_v2"
os_type = "Linux"
os_disk_size_gb = 10
}
}
resource "azurerm_container_registry" "terraform_training_acr" {
# registry name can only contain alpha numeric characters
name = "terraformtrainingacr"
location = "${var.tftranining_rg_location}"
resource_group_name = "${var.tftranining_rg_name}"
sku = "Basic"
admin_enabled = true
}
#We need to give AKS's Service principal "Contributor" role for accessing ACR
resource "azurerm_role_assignment" "aks_acr_pullimage" {
#scope on which we are to assign this role
scope = "${azurerm_container_registry.lterraform_training_acr.id}"
#this refers to a builtin role definition
role_definition_name = "AcrPull"
#passing AKS's service principal's object id
principal_id = "AKS SP Object ID"
}
是否可以在不将其作为变量传递的情况下在角色分配中引用 AKS 的服务主体的对象 ID。
我希望使用使用 AKS 创建的默认 SP。
这可以使用命令来完成。我们可以使用 terraform 做同样的事情吗? Get SP using az cli
【问题讨论】:
标签: azure terraform terraform-provider-azure