标签: terraform-provider-azure

在 Apple M1 上设置 terraform v0.14.0

有关如何在 Apple M1 上设置 Terraform v0.14.0 的任何指示,因为 tfenv 不支持 Apple M1 上的 v0.14.0

tfenv install v0.14.0
Installing Terraform v0.14.0
Downloading release tarball from https://releases.hashicorp.com/terraform/0.14.0/terraform_0.14.0_darwin_arm64.zip
curl: (22) The requested URL returned error: 403

Tarball download failed
Run Code Online (Sandbox Code Playgroud)

darwin terraform terraform-provider-azure apple-m1

19
推荐指数
2
解决办法
2万
查看次数

Terraform depends_on 与模块

我是 terraform 的新手,我在模块结构上创建了一个自定义的 azure 策略。每个策略代表一个自定义模块。我创建的模块之一是为创建的任何新 azure 资源启用诊断日志。但是,我需要一个存储帐户。(在启用诊断设置之前,我如何实现“depends_on”?或任何其他方法? 我想首先创建存储帐户,然后创建诊断设置模块。在main.tf(调用所有其他模块的地方)或资源内部(模块)?

谢谢您的帮助!!:)

下面的代码代表 main.tf 文件:

//calling the create storage account name

module "createstorageaccount" {

source = "./modules/module_create_storage_account"
    depends_on = [
    "module_enable_diagnostics_logs"
  ]

}
Run Code Online (Sandbox Code Playgroud)

这个代表创建存储帐户模块

resource "azurerm_resource_group" "management" {


  name     = "management-rg"
  location = "West Europe"
}

resource "azurerm_storage_account" "test" {
  name                     = "diagnostics${azurerm_resource_group.management.name}"
  resource_group_name      = "${azurerm_resource_group.management.name}"
  location                 = "${azurerm_resource_group.management.location}"
  account_tier             = "Standard"
  account_replication_type = "LRS"

  tags = {
    environment = "diagnostics"
  }
}

    depends_on = [
    "module_enable_diagnostics_logs"
  ]

Run Code Online (Sandbox Code Playgroud)

azure terraform terraform-provider-azure

18
推荐指数
2
解决办法
3万
查看次数

无法检索提供程序 Terraform Azure 的可用版本列表

基于 PR:https ://github.com/terraform-providers/terraform-provider-azurerm/pull/5325

需要 azurerm 提供程序版本 1.42.0,以便默认安装服务器版本 3.6 的 cosmosdb 帐户。为了实现这一目标,我在模板中添加了以下内容,不幸的是,该模板失败并出现以下错误。

提供商“azurerm”{版本=“〜> 1.42.0”}

hashicorp/azurerm:没有可用的版本与给定的约束相匹配 1.35.0,〜> 1.35.0,〜> 1.42.0,〜> 1.35.0 无法检索提供程序的可用版本列表

有人可以阐明这一点吗?我在这里缺少什么

azure azure-cosmosdb terraform-provider-azure

18
推荐指数
2
解决办法
7万
查看次数

基于变量的可选块

我正在为 编写某种包装模块azurerm_storage_account

azurerm_storage_account有可选块

static_website {
  index_document = string
  error_404_document = string
}
Run Code Online (Sandbox Code Playgroud)

我想根据变量设置它,但我不太确定该怎么做?条件运算符实际上不适用于块(例如static_website = var.disable ? null : { .. }

或者块是否以这样的方式工作,如果我设置index_documenterror_404_document,它与完全不设置块null相同?static_website

azurerm@2.x

TF@0.12.x

terraform terraform-provider-azure

17
推荐指数
1
解决办法
1万
查看次数

如何忽略块中属性的更改

我正在 Azure 中部署 Web 应用程序,我想忽略对site_config块中scm_type属性的更改。

在部署期间,scm_type属性设置为None,稍后我们将在 Azure 门户中将其更改为不同的内容。

我当前的 TF 代码如下所示:

resource "azurerm_app_service" "web_app" {
  count               = length(var.app_names)
  name                = var.app_names[count.index]
  location            = data.azurerm_resource_group.app_resource_group.location
  resource_group_name = data.azurerm_resource_group.app_resource_group.name
  app_service_plan_id = azurerm_app_service_plan.app_plan.id
  tags                = var.tags
  app_settings        = var.app_settings[count.index]

  site_config {
    always_on                 = true
    websockets_enabled        = var.websockets_enabled[count.index]
    use_32_bit_worker_process = var.use_32_bit_worker_process
    scm_type                  = "None"
  }

  lifecycle {
    ignore_changes = [
      site_config.0.scm_type
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望 terraform 计划在基础设施更新期间忽略scm_type 的变化,但它试图将其恢复为None。来自地形计划输出的行:

~ scm_type …

terraform terraform-provider-azure terraform0.12+

16
推荐指数
2
解决办法
2万
查看次数

在不同订阅下拥有 Terraform azure 状态文件

我在 Azure 中有两个订阅。我们称它们为 sub-dev 和 sub-prod。在 sub-dev 下,我有用于开发的资源(在资源组 rg-dev 中)和用于生产的 sub-prod 资源(在资源组 rg-prod 中)。

现在,我只想为开发和生产只有一个状态文件。我可以这样做,因为我使用 Terraform 工作区(开发和生产)。在 sub-dev (rg-dev) 下有一个名为 tfsate 的存储帐户。它有一个容器等。Azure 后端配置如下:

terraform {
  backend "azurerm" {
    resource_group_name  = "rg-dev"
    storage_account_name = "tfstate"
    container_name       = "tfcontainer"
    key                  = "terraform.tfstate" 
  }
}
Run Code Online (Sandbox Code Playgroud)

如果我想申请开发环境,我必须将 Az Cli 切换到子开发环境。同样,对于生产,我将不得不使用 sub-prod。我使用 az cli 切换默认订阅:

az account set -s sub-prod
Run Code Online (Sandbox Code Playgroud)

问题是状态的存储帐户在 sub-dev 而不是 sub-prod 下。terraform init当默认订阅设置为 sub-prod 时,我会在尝试(或应用)时遇到访问错误。

Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "tfstate": storage.AccountsClient#ListKeys: Failure …
Run Code Online (Sandbox Code Playgroud)

azure terraform terraform-provider-azure

13
推荐指数
2
解决办法
8568
查看次数

Terraform 的多个提供程序版本

有谁知道是否可以有一个使用多个提供程序版本的 Terraform 脚本?

例如,azurerm 版本 2.0.0 用于创建一个资源,而 1.4.0 用于创建另一个资源?我尝试指定提供程序,如下所示: https: //www.terraform.io/docs/configuration/providers.html

然而,它似乎不起作用,因为它试图解析同时满足 1.4.0 和 2.0.0 的单个提供程序。它的错误如下:

No provider "azurerm" plugins meet the constraint "=1.4.0,=2.0.0".
Run Code Online (Sandbox Code Playgroud)

我问这个问题是因为我们有一个很大的 Terraform 代码库,如果可行的话我想一点一点地迁移。

曾经有人提出过类似的问题,这里:Terraform: How to install multiple versions ofprovider plugins? 但没有得到有效答案

terraform terraform-provider-azure

12
推荐指数
2
解决办法
2万
查看次数

等待条件时terraform头盔释放超时

我正在使用terraform在azure中预配置一些资源,但似乎无法掌控安装nginx-ingress,因为它等待状态超时

  • helm_release.nginx_ingress:发生1个错误:

  • helm_release.nginx_ingress:rpc错误:代码=未知desc =发布nginx-ingress失败:等待条件超时

面对错误,Terraform不会自动回滚。相反,您的Terraform状态文件已使用成功完成的所有资源进行了部分更新。请解决以上错误,然后再次应用以逐步更改您的基础架构。主文件

data "azurerm_public_ip" "nginx_ingress" {
    name                = "xxxx-public-ip"
    resource_group_name = "xxxx-public-ip"
}

resource "azurerm_resource_group" "xxxx_RG" {
  name     = "${var.name_prefix}"
  location = "${var.location}"
}

resource "azurerm_kubernetes_cluster" "k8s" {
    name                    = "${var.name_prefix}-aks"
    kubernetes_version      = "${var.kubernetes_version}"
    location                = "${azurerm_resource_group.xxxx_RG.location}"
    resource_group_name     = "${azurerm_resource_group.xxxx_RG.name}"
    dns_prefix              = "AKS-${var.dns_prefix}"

    agent_pool_profile {
        name                = "${var.node_pool_name}"
        count               = "${var.node_pool_size}"
        vm_size             = "${var.node_pool_vmsize}"
        os_type             = "${var.node_pool_os}"
        os_disk_size_gb     = 30
    }

    service_principal {
        client_id           = "${var.client_id}"
        client_secret       = "${var.client_secret}"
    }

    tags = {
        environment = "${var.env_tag}"
    } …
Run Code Online (Sandbox Code Playgroud)

terraform kubernetes-helm terraform-provider-azure azure-aks nginx-ingress

11
推荐指数
1
解决办法
1220
查看次数

terraform plan 返回错误:不支持的参数

我有以下三个文件:main.tf、variables.tf 和 dev.auto.tfvars

main.tf中的片段

module "sql_vms" {
  source                  = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/"
  rg_name                 = var.resource_group_name
  location                = module.resource_group.external_rg_location
  vnet_name               = var.virtual_network_name
  subnet_name             = var.sql_subnet_name
  app_nsg                 = var.application_nsg
  vm_count                = var.count_vm
  base_hostname           = var.sql_host_basename
  sto_acc_suffix          = var.storage_account_suffix
  vm_size                 = var.virtual_machine_size
  vm_publisher            = var.virtual_machine_image_publisher
  vm_offer                = var.virtual_machine_image_offer
  vm_sku                  = var.virtual_machine_image_sku
  vm_img_version          = var.virtual_machine_image_version
  username                = var.username
  password                = var.password
}
Run Code Online (Sandbox Code Playgroud)

来自variables.tf的片段

variable "app_subnet_name" {
  type    = string
}

variable "sql_subnet_name" {
  type    = string
}
Run Code Online (Sandbox Code Playgroud)

来自dev.auto.tfvars的片段

app_subnet_name = "subnet_1"

sql_subnet_name = …
Run Code Online (Sandbox Code Playgroud)

terraform-provider-azure

10
推荐指数
2
解决办法
6万
查看次数

如何使用 terraform 0.13.5 检查列表中是否存在该值?

我需要检查变量中是否存在值,并基于此我需要创建资源。如果value_list没有这些,values('abc','def','ghi')则不应创建资源。

我在这里尝试的是:

  1. 将字符串变量转换为列表
  2. 检查列表是否具有值“abc”或“def”或“ghi”。如果value_list包含任何一个值,则继续执行后续步骤以创建资源。
  3. 如果value_list没有这些,values('abc','def','ghi')则不应创建资源。

变量.tf

variable "value_list" {
    default = "abc,def,ghi"
    type= string
}
Run Code Online (Sandbox Code Playgroud)

资源.tf

resource "azurerm_kubernetes_cluster_node_pool" "user" {
  value_list = ${split(",", var.value_list)}
  count = "${contains(value_list,"abc") ? 1 : 0 || contains(value_list,"def") ? 1 : 0 || contains(value_list,"ghi") ? 1 : 0 
}
Run Code Online (Sandbox Code Playgroud)

错误:

该语言中不使用该字符。预期是表达式的开头,但发现了无效的表达式标记。

如何检查 value_list 是否具有所需的值?

contains azure-resource-manager terraform terraform-provider-azure azure-rm

10
推荐指数
1
解决办法
4万
查看次数