我正在尝试使用 Terraform 创建 IAM 角色和 IAM 策略。
\n我收到此错误:
\n\xe2\x94\x82 Error: error creating IAM Role (asg-domain-join-policy): MalformedPolicyDocument: Has prohibited field Resource\n \n status code: 400, request id: 53fa1ae0-f22f-4f2e-8aa6-1947421eae9b\n\n with aws_iam_role.ad_join_role,\n on iam.tf line 30, in resource "aws_iam_role" "ad_join_role":\n 30: resource "aws_iam_role" "ad_join_role" {\nRun Code Online (Sandbox Code Playgroud)\n我当前的 IAM 角色代码如下:
\nresource "aws_iam_role" "ad_join_role" {\n name = "asg-domain-join-policy"\n assume_role_policy = data.aws_iam_policy_document.asg_domain_join_policy.json\n permissions_boundary = "arn:aws:iam::${var.account_id}:policy/****"\n}\nRun Code Online (Sandbox Code Playgroud)\nIAM 策略的代码如下:
\ndata "aws_iam_policy_document" "asg_domain_join_policy" {\n statement {\n actions = [\n "ssm:DescribeAssociation",\n "ssm:GetDocument",\n "ssm:ListAssociations",\n "ssm:UpdateAssociationStatus",\n "ssm:UpdateInstanceInformation",\n …Run Code Online (Sandbox Code Playgroud) 我尝试解析以下变量:
变量.tf
variable "rbac_roles" {
type = object(
{
view = list(object({
group_name = string,
group_id = string,
namespaces = list(string)
})),
edit = list(object({
group_name = string,
group_id = string,
namespaces = list(string)
})),
admin = list(object({
group_name = string,
group_id = string,
namespaces = list(string)
}))
}
)
}
Run Code Online (Sandbox Code Playgroud)
变量.tfvars
rbac_roles = {
view = [
{
group_name = "group1",
group_id = "123",
namespaces = ["default", "namespace1"]
},
{
group_name = "group2",
group_id = "456",
namespaces = ["namespace2"] …Run Code Online (Sandbox Code Playgroud) 我想创建多个存储帐户,并在每个存储帐户内创建一些容器。如果我想要 3 个存储帐户,我总是想在这 3 个存储帐户中创建容器 a 和容器 b
例如就是这样。存储帐户列表[“sa1”,“sa2”,“sa3”]。
resource "azurerm_storage_account" "storage_account" {
count = length(var.list)
name = var.name
resource_group_name = module.storage-account-resource-group.resource_group_name[0]
location = var.location
account_tier = var.account_tier
account_kind = var.account_kind
Run Code Online (Sandbox Code Playgroud)
然后是容器块
resource "azurerm_storage_container" "container" {
depends_on = [azurerm_storage_account.storage_account]
count = length(var.containers)
name = var.containers[count.index].name
container_access_type = var.containers[count.index].access_type
storage_account_name = azurerm_storage_account.storage_account[0].name
Run Code Online (Sandbox Code Playgroud)
容器变量:
variable "containers" {
type = list(object({
name = string
access_type = string
}))
default = []
description = "List of storage account containers."
}
Run Code Online (Sandbox Code Playgroud)
列表变量
variable "list" { …Run Code Online (Sandbox Code Playgroud) 对于以下 Terraform 代码 - 我希望最终得到 2 个测试沙箱开发实例和 1 个测试沙箱测试实例。我希望能够从地图值中得出计数instance_count。
我尝试过使用,count但 Terraform 不允许for_each.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
variable "instance_name" {
description = "Value of the Name tag for the EC2 instance"
type = string
default = "ChangedName"
}
variable "aws_region" {
description = "AWS Region"
type = string
default = "eu-west-2"
}
variable "instance_size_small" {
description = "Instance …Run Code Online (Sandbox Code Playgroud) 在我的 terraform 代码中,我想将以下地图列表合并到一张地图中。地图的初始列表如下所示。有没有办法做到这一点?如果没有,是否可以以某种方式在 for_each 中使用原始地图列表?据我所知,它只接受一组字符串或映射。我尝试重组它,但没有运气。
[
{
"repo1" = {
"description" = "repo1 for something"
"enforce_branch_policies" = true
"name" = "repo1"
}
}
{
"repo2" = {
"description" = "repo2 for something"
"enforce_branch_policies" = true
"name" = "repo2"
}
}
]
Run Code Online (Sandbox Code Playgroud)
预计地图:
{
"repo1" = {
"description" = "repo1 for something"
"enforce_branch_policies" = true
"name" = "repo1"
}
"repo2" = {
"description" = "repo2 for something"
"enforce_branch_policies" = true
"name" = "repo2"
}
}
Run Code Online (Sandbox Code Playgroud) 我收到了 SwaggerHub 上托管的 OpenAPI 3.0.1 定义的链接,并被告知要部署它。在 Terraform 方面,我看到太多让我困惑的资源,我不确定该使用哪一个。通过 Terraform 部署已在 OpenAPI 定义中配置的 API 网关的最直接方法是什么?是否有资源可以让我向 API 网关提供 OpenAPI 定义 URL,或者我必须将实际的 JSON 复制粘贴到某处?
在我的 Macbook 上运行 terraform init 时出现以下错误。有人可以帮忙吗?
提供程序registry.terraform.io/hashicorp/template v2.2.0 没有适用于您当前平台darwin_arm64 的软件包。
我的 terraform 版本是 1.1.4。
我的provider.tf 文件中已经有最新版本:
required_providers {
archive = {
source = "hashicorp/archive"
version = "2.2.0"
}
aws = {
source = "hashicorp/aws"
version = "3.72.0"
}
}
Run Code Online (Sandbox Code Playgroud)
然而,当我检查terraform version我的终端时,我得到了这个:
Terraform v1.0.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v3.72.0
Your version of Terraform is out of date! The latest version
is 1.1.4. You can update by downloading from https://www.terraform.io/downloads.html
Run Code Online (Sandbox Code Playgroud)
我已经尝试过terraform init -upgrade,但这也没有什么区别。我还从网站手动下载了 terraform 的新版本,但我的终端仍然显示 1.0.7。
由于旧的 Terraform 版本,我面临其他错误。如何使用终端更新到最新版本?
我已经尝试部署自我管理节点 EKS 集群有一段时间了,但没有成功。我现在遇到的错误是 EKS 插件:
错误:创建 EKS 插件时出错 (DevOpsLabs2b-dev-test--eks:kube-proxy):InvalidParameterException:不支持指定的插件版本,AddonName:“kube-proxy”,ClusterName:“DevOpsLabs2b-dev-test-- eks", Message_: "不支持指定的插件版本" } 在 .terraform/modules/eks-ssp-kubernetes-addons/modules 上使用 module.eks-ssp-kubernetes-addons.module.aws_kube_proxy[0].aws_eks_addon.kube_proxy /kubernetes-addons/aws-kube-proxy/main.tf 第 19 行,在资源“aws_eks_addon”“kube_proxy”中:
coredns 也会重复此错误,但 ebs_csi_driver 会抛出:
错误:创建期间返回意外的 EKS 附加组件 (DevOpsLabs2b-dev-test--eks:aws-ebs-csi-driver) 状态:等待状态变为“ACTIVE”时超时(最后状态:“DEGRADED”,超时: 20m0s) [警告] 再次运行 terraform apply 将删除 kubernetes 插件并尝试再次创建它,有效清除以前的插件配置
我的 main.tf 看起来像这样:
terraform {
backend "remote" {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.66.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.7.1"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.4.1" …Run Code Online (Sandbox Code Playgroud) amazon-web-services kubernetes terraform terraform-provider-aws amazon-eks
我正在尝试从 SNS codestar-notifications 为 AWS lambda 创建触发器
。
使用控制台创建触发器时,它会自动添加对 SNS 主题的订阅。
。此外,这也可以在另一个方向上工作,即如果我通过显式添加其 arn 来创建 SNS 作为 Lambda 函数的订阅,它会自动将触发器链接到 Lambda 函数。
但是当使用 terraform 创建订阅时,如下所示:
resource "aws_sns_topic_subscription" "subscribe_lambda_to_first_topic" {
topic_arn = module.first_topic.sns-topic-detail.arn
protocol = "lambda"
endpoint = module.lambda_function.lambda_function.arn
}
Run Code Online (Sandbox Code Playgroud)
它不会在 AWS Lambda 中创建触发器。
我尝试使用 Terraform 中的事件源映射创建触发器,如下所示
resource "aws_lambda_event_source_mapping" "lambda_source" {
event_source_arn = module.first_topic.sns-topic-detail.arn
function_name = module.lambda_function.lambda_function.arn
starting_position = "LATEST"
}
Run Code Online (Sandbox Code Playgroud)
它向我抛出一个错误,说它只能用于
错误:创建 Lambda 事件源映射时出错(arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda):InvalidParameterValueException:无法识别的事件源,必须是 kinesis、dynamodb 流或 sqs 。不支持的源 arn : arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda { RespMetadata: { StatusCode: 400, RequestID: "83bf57cb-b50d-49a8-9547-72fac69778d1" },Message_:“无法识别的事件源,必须是 kinesis、dynamodb 流或 sqs。不支持的源 …
amazon-web-services amazon-sns aws-lambda terraform terraform-provider-aws
terraform ×10
azure ×2
kubernetes ×2
amazon-eks ×1
amazon-sns ×1
apple-m1 ×1
aws-lambda ×1
cloud ×1
flatten ×1
for-loop ×1
hashicorp ×1
list ×1
object ×1
openapi ×1
provider ×1
version ×1