标签: terraform-provider-azure

如何在 Azure DevOps/VSTS 的 Terraform 文件中引用变量

我创建了一个简单的管道。带有 Azure DevOps Build管道的Github 存储库。

我在 Github 私有存储库中的 ax.tf 文件中定义了以下提到的变量:

ARM_CLIENT_ID
ARM_CLIENT_SECRET
ARM_SUBSCRIPTION_ID
ARM_TENANT_ID
Run Code Online (Sandbox Code Playgroud)

构建管道有一个简单的命令行作业,如下所示:

sudo apt install wget

wget https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip

sudo apt-get install unzip

unzip terraform_0.11.11_linux_amd64.zip

terraform init

terraform plan -var-file=terraform.tfvars -out=ax.plan

terraform apply ax.plan

terraform destroy -auto-approve
Run Code Online (Sandbox Code Playgroud)

我想知道如何在 Terraform ax.tf 文件中引用这些 Build 变量?

我按照 Azure DevOps 文档做了类似下面的事情,但它不起作用:

variable "ARM_SUBSCRIPTION_ID" {
    default="$(Build.ARM_SUBSCRIPTION_ID)"
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它没有按预期工作,并在以下执行级别停止:

[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
[0m[32m
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required …
Run Code Online (Sandbox Code Playgroud)

terraform azure-devops terraform-provider-azure

7
推荐指数
1
解决办法
6184
查看次数

如何在 Hashicorp Terraform 中配置环境变量

我对 Terraform 还是很陌生,尽管我已经浏览了 Hashicorp 网站上提供的所有教学模块。

目前,我正在努力理解如何设置环境变量。我知道如何在 main.tf config ( access_key = "${var.access_key}") 中引用变量,并且我知道如何将该访问密钥保存到一个单独的文件并引用它,但是我不明白(并且找不到任何文档/说明) 是如何设置环境变量,因此我不必将访问密钥保存到文件中。

有谁知道如何最好地做到这一点?

terraform terraform-provider-azure

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

Azure 存储帐户防火墙规则阻止使用 azure devops 进行 terraform 部署

我想使用 Azure DevOps 管道部署我的 terraform 基础结构,但我遇到了存储帐户防火墙的问题。以下是存储帐户的示例:

resource "azurerm_storage_account" "storage_account" {
  name                              = "mystorageaccount"
  resource_group_name               = "myresourcegroup"
...
  network_rules {
      default_action             = "Deny"
      bypass                     = ["AzureServices", "Logging"]
      ip_rules                   = ["192.1.1.1"]
  }
}
Run Code Online (Sandbox Code Playgroud)

存储帐户的初始创建成功,但由于防火墙规则,所有进一步操作(例如添加容器)都失败并出现未经授权的异常。

不幸的是,为“AzureServices”添加绕过规则不起作用。

我必须添加防火墙规则的原因是因为公司安全准则,所以我不能删除它。

有没有办法用 azure devops 处理存储帐户防火墙规则?

azure terraform azure-devops terraform-provider-azure

7
推荐指数
1
解决办法
1377
查看次数

如何使用 terraform local-exec 运行多个命令

我正在尝试使用 local-exec 配置程序使用 terraform 运行一些 az cli 命令,但我不断遇到错误:

Error: Invalid expression

On modules/eventgrid/main.tf line 68: Expected the start of an expression, but
found an invalid expression token.

Run Code Online (Sandbox Code Playgroud)

这是我的代码:

resource "null_resource" "eg-role-assignment" {
  provisioner "local-exec" {
    
    interpreter = ["/bin/bash", "-c"]
    command = <<EOT 
              "az account set --subscription foo"
              "az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned"
    EOT

    environment = {
      RESOURCE_GROUP = "RG_${var.platform_tag}_${var.product_code}_PUBLISH_${var.environment}_${var.location_code_primary}"
      EVENTGRID_NAME = "EG-${var.platform_tag}-${var.product_code}-${var.environment}-${var.location_code_primary}-domain"

    }
  
  }
}
Run Code Online (Sandbox Code Playgroud)

有人可以指导我出什么问题吗?

azure-cli terraform terraform-provider-azure

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

使用Terraform导入Azure上的现有资源

我在Azure上有一个现有的资源组,其上运行了一个VM,并且一直在使用Terraform来尝试将资源导入到我的状态文件中.

我已经设置了一个框架文件,据我所知,一旦我导入TF应该使用Azure中我的资源组中的值填充它

resource "azurerm" "example" {
# ...instance configuration...
  name = "MyResourceGroup"

}
Run Code Online (Sandbox Code Playgroud)

命令我从CLI运行:

terraform import azurerm_resource_group.MyResourceGroup/subscriptions/MySubscriptionNumber/resourceGroups/MyResourceGroup
Run Code Online (Sandbox Code Playgroud)

来自Terraform的消息:

The import command expects two arguments.
Usage: terraform import [options] ADDR ID

  Import existing infrastructure into your Terraform state.

  This will find and import the specified resource into your Terraform
  state, allowing existing infrastructure to come under Terraform
  management without having to be initially created by Terraform.

  The ADDR specified is the address to import the resource to. Please
  see the documentation …
Run Code Online (Sandbox Code Playgroud)

azure azure-virtual-machine terraform terraform-provider-azure

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

在 Terraform 远程后端使用变量

# Using a single workspace:
terraform {
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "company"

    workspaces {
      name = "my-app-prod"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

对于 Terraform 远程后端,是否有一种方法可以使用变量来指定组织/工作区名称而不是那里的硬编码值?

Terraform 文档似乎 也没有提及任何相关内容。

terraform terraform-provider-azure terraform-remote-state

6
推荐指数
1
解决办法
2695
查看次数

azurerm_app_service v2 如何启用 v2 的身份验证设置

我已经使用 terraform 创建了一个 azure 应用程序服务,默认它选择旧样式的 AUTH 设置。正如微软建议的那样,旧的设置将在今年年底被删除,我们希望迁移到新的 AUTH 设置。我没有看到任何有关它的文档。当我手动升级其中一项应用程序服务的 AUTH 设置时,terraform 无法再更新给定的应用程序服务

下面是我用来创建应用程序服务的代码片段。这将创建具有 AUTH Version1 的应用程序服务。

  resource "azurerm_app_service" "as" {
  for_each            = var.appservice
  name                = lookup(each.value, "appservice_name")
  location            = var.location
  resource_group_name = var.resource_group_name
  app_service_plan_id = var.app_service_plan_id
  https_only          = lookup(each.value, "https_only", null)
  client_cert_enabled = lookup(each.value, "client_cert_enabled", false)
  tags                = var.standard_tags

  dynamic "site_config" {
    for_each = lookup(each.value, "site_config",[])
    content {
      always_on                 =  lookup(site_config.value, "always_on", true)
      app_command_line          =  lookup(site_config.value, "app_command_line", null)
      auto_swap_slot_name       =  lookup(site_config.value, "auto_swap_slot_name", null)
  
      dynamic "cors" {
        for_each = lookup(site_config.value, "cors", …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-azure

6
推荐指数
1
解决办法
3405
查看次数

在 terraform 云中运行的 azure cli $Path 错误

第一次设置 terraform cloud 并收到此错误。不知道为什么在我的本地计算机上安装了 azure CLI 并设置了路径,但我认为与在 terraform 云平台中设置它有关。

Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
with provider["registry.terraform.io/hashicorp/azurerm"]
on versions.tf line 21, in provider "azurerm":

provider "azurerm" {
Run Code Online (Sandbox Code Playgroud)

我当前的tf代码

版本.tf

terraform {

  cloud {
    organization = "myorg"

    workspaces {
      name = "dev"
    }
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version …
Run Code Online (Sandbox Code Playgroud)

terraform terraform-provider-azure terraform-cloud

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

Terraform 警告:警告:“use_microsoft_graph”:[已弃用] 此字段现在默认为“true”,并将在 Terraform Core v1.3 中删除

我创建了一个 Terraform 配置来创建资源组。这使用后端提供程序配置,因此 tfstate 文件将在共享位置而不是本地创建。

当我应用 plan terraform plan 时,我收到以下警告。

警告:“use_microsoft_graph”:[已弃用]true由于 Microsoft 弃用 ADAL,此字段现在默认为 Terraform Core v1.3,并将在 v1.3 中删除。配置文件如下。

# Terraform Block
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.0"
    }
  }

  # Terraform State Storage to Azure Storage Container
  backend "azurerm" {
    resource_group_name  = "storage-rg"
    storage_account_name = "tfstatetrial"
    container_name       = "tfstatefiles"
    key                  = "terraform.tfstate"
  }

}

# Provider Block
provider "azurerm" {
  features {}
}

# Resource-1: …
Run Code Online (Sandbox Code Playgroud)

terraform-provider-azure

6
推荐指数
1
解决办法
2964
查看次数

定位除 terraform 中的资源之外的所有资源(与“-target”参数相反)

我的 terraform 配置至少管理 20 个资源,我想部署除一个之外的所有资源,我知道我可以添加“-target”参数,但我必须指定所有资源的名称(至少 20 个资源的名称) resources)以“-target”为目标对我来说这是一个问题,因为我经常在我的terraform配置中添加/删除资源,所以我需要是否有一个与“-target”相反的解决方案来仅指定一个资源应用 terraform 配置时被忽略。

PS:我不想删除我的资源配置被忽略

terraform terraform-provider-azure terraform0.12+

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