我正在尝试创建一个包含多个安全规则的网络安全组。这个想法是创建一个列表变量(端口范围)并在 .tf 文件中插入列表项。下面的脚本抛出一个错误“priority.
"Error: azurerm_network_security_group.k8hway: security_rule.0: invalid or unknown key: count"
Run Code Online (Sandbox Code Playgroud)
下面是 Terraform 代码:
resource "azurerm_network_security_group" "NSG" {
name = "NSG-Demo"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
security_rule {
count = "${length(var.inbound_port_ranges)}"
name = "sg-rule-${count.index}"
direction = "Inbound"
access = "Allow"
priority = "(100 * (${count.index} + 1))"
source_address_prefix = "*"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "${element(var.inbound_port_ranges, count.index)}"
protocol = "TCP"
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试将 .net core 2.2 webapi 发布到我的 azure 应用程序服务(通过使用 Azure 应用程序服务部署的 azure devops 或通过 Visual Studio 发布方法)时,我不断收到:“您正在查找的资源已被删除,其名称已被删除已更改,或暂时不可用。”
但是当我直接使用 Visual Studio 发布它(没有包或 zip 配置)时,它就可以工作了。(但我们不能继续这样做,因为我们需要它在 azure devops 管道上工作)。
我尝试使用 dotnet build/publish 和 vsbuild 以不同的方式构建项目。我还尝试使用不同的发布方法(zip、package、web 部署)。
我仔细检查了生成的 xml 文件(deploy.cmd、deploy-readme、parameters、setparametersa 和 sourcemanifest),检查是否存在错误的命名问题,或者文件夹结构是否不正确,但一切都正确匹配。我的项目所在的 zip 文件也与所有生成的 xml 文件(根)位于同一位置。
奇怪的是,它之前可以正常工作,而我们正在使用 terraform 来生成天蓝色资源。所以我们扔掉了手动制作的资源并使用 terraform 重新制作了它们,然后我们得到了错误。我们没有改变管道上的任何内容。
yaml 从管道构建代码:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true …Run Code Online (Sandbox Code Playgroud) msbuild webdeploy azure-web-app-service azure-devops terraform-provider-azure
我有一个变量var.delete_retention_policy_days。如果该变量设置为,0那么我不希望启用保单天数块。有没有一种巧妙的方法可以在地形中做到这一点?
delete_retention_policy {
days = var.delete_retention_policy_days
}
Run Code Online (Sandbox Code Playgroud)
这是完整资源的示例
resource "azurerm_storage_account" "example2" {
name = var.azurerm_storage_account_name
resource_group_name = azurerm_resource_group.parameters.name
location = azurerm_resource_group.parameters.location
account_tier = var.azurerm_storage_account_account_tier
account_replication_type = var.azurerm_storage_account_account_replication_type
allow_blob_public_access = var.azurerm_storage_account_allow_blob_public_access
blob_properties {
delete_retention_policy {
days = var.delete_retention_policy_days
}
versioning_enabled = true
change_feed_enabled = true
}
Run Code Online (Sandbox Code Playgroud) 我们通过 Jenkins 在 Azure 租户中部署资源,Jenkins 使用 terraform 来配置基础设施资源。我们使用同一租户中的服务主体进行身份验证和基础设施配置。在我们的基础设施部署中,我们还与已部署的新 Vnet 以及拥有所有基础设施资源(如监控和日志记录平台)的中央 VNET 创建 VNET 对等互连。现在我们有一个用例,通过使用相同的 Jenkins 和 terraform 脚本,我们希望在不同的租户上配置资源。这可以通过使用远程租户的服务主体来完成。但现在的问题是服务主体TenantB无权创建网络资源TenantA。为了实现这一点,服务主体TenantB应该能够访问 中的 Vnet TenantA。我正在寻找文档或指导,我们如何才能访问TenantB我们的服务主体TenantA?
azure azure-active-directory terraform terraform-provider-azure sre
我正在尝试使用以下代码为我的服务主体创建 Client_secret:
data "azuread_service_principal" "existing_SP" {
display_name = "TestAppRegistration"
}
resource "azuread_service_principal_password" "Client_Secret" {
service_principal_id = data.azuread_service_principal.existing_SP.object_id
}
Run Code Online (Sandbox Code Playgroud)
执行 terraform-apply 它已成功创建,但我在应用程序注册的“秘密和证书”部分中没有看到它:
但是当我检查 tfstate 时,它显示为服务主体创建的值,但对象 ID 与同一应用程序注册中存在的企业应用程序相同:
所以,我的问题是:
我正在尝试找出一种向资源添加递增数字的方法。
这是我的代码片段。我想让优先级成为一个递增的数字,而不是传递一个固定的数字。
当前代码
resource "azurerm_firewall_network_rule_collection" "netrc" {
for_each = {for network_rule_collection in var.network_rule_collections: network_rule_collection.name => network_rule_collection}
name = "netrc-${each.key}"
azure_firewall_name = var.afw_name
resource_group_name = var.resource_group_name
priority = var.priority
action = each.value.action
Run Code Online (Sandbox Code Playgroud)
基本上,我想看起来像这样:
priority = (each.index * 10) + 140
Run Code Online (Sandbox Code Playgroud)
我尝试使用each.key,但在这个模块中,each.key是一个字符串。
我也尝试了计数器,但不能将计数器与 for_each 循环结合起来。
有什么想法或建议吗?
编辑
我最终按照下面的建议使用了索引。
priority = (index(var.application_rule_collections, each.value) + 100)
Run Code Online (Sandbox Code Playgroud) 当我试图让我的 terraform 代码更加动态时,我遇到了问题。请重点关注“vm2”配置。
\n1. 工作场景
\n在我的 locals.tf 中我有:
\n vms_configurations = {\n "vm1" = {\n size = "Standard_E4ds_v5"\n vm_backup_policy_frequency = "Weekly"\n vm_backup_weekly = {\n count = 4\n weekdays = ["Sunday"]\n }\n }\n "vm2" = {\n size = "Standard_DS12_v2"\n vm_backup_policy_frequency = "Daily"\n vm_backup_daily_policy_retention = 7\n vm_backup_weekly = {\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n在我对备份模块的调用中,我有:
\n...\n vm_backup_weekly = each.value["vm_backup_weekly"]\n vm_backup_daily_policy_retention = each.value["vm_backup_policy_frequency"] == "Daily" ? each.value["vm_backup_daily_policy_retention"] : null\n...\nRun Code Online (Sandbox Code Playgroud)\n一切都很好。
\n2. 失败场景
\n但是,如果我尝试从 locals.tf 中的“vm2”配置中删除“vm_backup_weekly”,如下所示:
\n vms_configurations = …Run Code Online (Sandbox Code Playgroud) 我尝试使用 terraform 将后端和前端部署为 azure 中的容器应用程序。
前端需要将后端的 URL 作为环境变量。
这可能一次性完成吗?
例如,使用 docker-compose 时,容器的内部主机名是预先确定的,或者是 kubernetes 中的服务。
我现在唯一能想到的就是应用该计划,等待容器应用程序创建并接收主机名,然后更改我的.tf文件并再次应用。但必须有更好的解决方案。
azure terraform terraform-provider-azure azure-container-apps
我们正在使用 Terraform 将 Web 应用程序部署到 Azure,并希望不再使用 web.config 进行配置设置。我相信我们可以在部署时使用资源app_settings参数来实现这些azurerm_app_service,但尝试找到如何正确格式化它的示例。
使用kubectl我们可以创建docker registry authentication secret如下
kubectl create secret docker-registry regsecret \
--docker-server=docker.example.com \
--docker-username=kube \
--docker-password=PW_STRING \
--docker-email=my@email.com \
Run Code Online (Sandbox Code Playgroud)
我如何secret使用创建它terraform,我看到了这个链接,它在实例data流中创建,我从那里获取所需的数据,我创建了如下所示的内容terraformkubernetesazure
resource "kubernetes_secret" "docker-registry" {
metadata {
name = "registry-credentials"
}
data = {
docker-server = data.azurerm_container_registry.docker_registry_data.login_server
docker-username = data.azurerm_container_registry.docker_registry_data.admin_username
docker-password = data.azurerm_container_registry.docker_registry_data.admin_password
}
}
Run Code Online (Sandbox Code Playgroud)
似乎是错误的,因为图像没有被拉出。我在这里错过了什么。
无法使用 terraform 在 azure 中为 nsg 安全规则提供目标端口范围。Terraform v0.12.28provider.azurerm v2.18.0
security_rule {
name = "databricks-control-plane-inbound-rule"
priority = 110
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = 225557
}
Run Code Online (Sandbox Code Playgroud)
错误:发送请求失败:StatusCode=400 -- 原始错误:
代码 =“SecurityRuleInvalidPortRange”消息 =“安全规则的端口范围无效。提供的值:225557。值应为整数或带有“-”分隔符的整数范围。有效范围0-65535。” 详情=[]
我是 terraform 新手,想要更改网络上的子网,但遇到了一个奇怪的错误。\ngoogle 什么也没得到。这是我要输入的内容(更改 main.tf 和运行计划后)
\nterraform apply -replace="azurerm_subnet.subnet1"\nTerraform will perform the following actions:\n\n # module.network.azurerm_subnet.subnet[0] will be updated in-place\n ~ resource "azurerm_subnet" "subnet" {\n ~ address_prefixes = [\n - "10.0.2.0/24",\n + "10.0.4.0/24",\n ]\n id = \n "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/lab- \n resources/providers/Microsoft.Network/virtualNetworks/acctvnet/subnets/subnet1"\n name = "subnet1"\n # (7 unchanged attributes hidden)\n }\n\n Plan: 0 to add, 1 to change, 0 to destroy.\n\n Do you want to perform these actions?\n Terraform will perform the actions described above.\n Only 'yes' will be accepted to …Run Code Online (Sandbox Code Playgroud) 我有一组变量terraform.tfvars:
resource_groups = {
cow = {
name = "Cow"
location = "eastus"
},
horse = {
name = "Horse"
location = "eastus"
},
chicken = {
name = "Chicken"
location = "westus2"
},
}
Run Code Online (Sandbox Code Playgroud)
我的main.tf样子是这样的:
...
module "myapp" {
source = "./modules/myapp"
resource_groups = var.resource_groups
}
variable "resource_groups" {}
...
Run Code Online (Sandbox Code Playgroud)
./modules/myapp.main.tf看起来像这样:
module "resource_group" {
source = "../myapp.resource_group"
resource_groups = var.resource_groups
for_each = {
for key, value in try(var.resource_groups, {}) : key => value
if …Run Code Online (Sandbox Code Playgroud) terraform ×10
azure ×7
azure-devops ×2
azure-aks ×1
foreach ×1
if-statement ×1
kubernetes ×1
msbuild ×1
sre ×1
terragrunt ×1
webdeploy ×1