我正在学习地形。我正在尝试创建一个新的 Lambda 函数。我意识到我还需要创建一个 IAM 角色。所以我正在尝试使用 Terraform 来做这两项工作。但它不允许我创建角色。
这是我的 Terraform 文件
provider "aws" {
profile = "default"
region = "eu-west-1"
}
data "aws_iam_policy" "AWSLambdaBasicExecutionRole" {
arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role" "terraform_function_role" {
name = "terraform_function_role"
assume_role_policy = "${data.aws_iam_policy.AWSLambdaBasicExecutionRole.policy}"
}
resource "aws_lambda_function" "terraform_function" {
filename = "terraform_function.zip"
function_name = "terraform_function"
handler = "index.handler"
role = "${aws_iam_role.terraform_function_role.id}"
runtime = "nodejs8.10"
source_code_hash = "${filebase64sha256("terraform_function.zip")}"
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
Error creating IAM Role terraform_function_role: MalformedPolicyDocument: Has prohibited field Resource
status code: 400
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
这是一个新手问题,但我刚刚开始使用 Terraform / Terragrunt 进行 GCP 配置,我发现获取 GCP 凭据的工作流程非常混乱。我来自只使用 AWS,在那里获取凭证并在 AWS CLI 中配置它们非常简单。
基本上,Google Cloud Provider 文档指出您应该provider像这样定义一个块:
provider "google" {
credentials = "${file("account.json")}"
project = "my-project-id"
region = "us-central1"
zone = "us-central1-c"
}
Run Code Online (Sandbox Code Playgroud)
该credentials字段显示我(显然)必须生成一个服务帐户,并在我的文件系统上的某处保留一个 JSON。
但是,如果我运行该命令gcloud auth application-default login,则会生成一个位于~/.config/gcloud/application_default_credentials.json;的令牌。或者我也可以使用gcloud auth login <my-username>. 从那里我可以使用gcloud命令从命令行访问 Google API(这也是 Terraform 在幕后所做的)。
那么为什么 Terraform 提供程序需要服务帐户的 JSON 文件呢?为什么不能只使用gcloudCLI 工具已经在使用的凭据?
顺便说一句,如果我将 Terraform 配置为指向该application_default_credentials.json文件,则会出现以下错误:
正在初始化模块...
正在初始化后端...
错误:无法获取现有工作区:查询 Cloud Storage 失败:获取 …
google-cloud-platform terraform terragrunt terraform-provider-gcp
我正在编写用于为 AWS StepFunctions 创建 IAM 角色的 terraform。应该是什么价值主要 在assume_role_policy
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "stepfunctions.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
Run Code Online (Sandbox Code Playgroud)
我收到错误
错误:创建 IAM 角色 my_utility_sfn 时出错:MalformedPolicyDocument:策略中的委托人无效:“SERVICE”:“stepfunctions.amazonaws.com”
我的简单 terraform 文件是:
provider "aws" {
region = "region"
access_key = "key"
secret_key = "secret_key"
}
terraform {
backend "s3" {
# Replace this with your bucket name!
bucket = "great-name-terraform-state-2"
key = "global/s3/terraform.tfstate"
region = "eu-central-1"
# Replace this with your DynamoDB table name!
dynamodb_table = "great-name-locks-2"
encrypt = true
}
}
resource "aws_s3_bucket" "terraform_state" {
bucket = "great-name-terraform-state-2"
# Enable versioning so we can see the full revision history of our
# state files
versioning {
enabled = …Run Code Online (Sandbox Code Playgroud) 我们有 cronjob 和 shell 脚本,我们希望在使用 terraform 创建实例时将它们复制或上传到 aws ec2 实例。
我们尝试了
provisioner "file" {
source = "abc.sh"
destination = "/home/ec2-user/basic2.sh"
}
Run Code Online (Sandbox Code Playgroud)
data "template_file" "userdata_line" {
template = <<EOF
#!/bin/bash
mkdir /home/ec2-user/files2
cd /home/ec2-user/files2
sudo touch basic2.sh
sudo chmod 777 basic2.sh
base64 basic.sh |base64 -d >basic2.sh
EOF
}
Run Code Online (Sandbox Code Playgroud)
尝试了所有选项,但没有一个工作。
你能帮忙或建议吗?
我是 terraform 的新手,长期以来一直在这方面苦苦挣扎。
我想将 EFS 与 fargate 一起使用,但在任务开始时出现此错误:
ResourceInitializationError: failed to invoke EFS utils commands to set up EFS volumes: stderr: Failed to resolve "fs-xxxxx.efs.eu-west-1.amazonaws.com" - check that your file system ID is correct
Run Code Online (Sandbox Code Playgroud)
我已经检查了文件系统 ID,它是正确的...我如何获得有关此错误的更多信息?它可能与安全组有关吗?
这是我与 terraform 一起使用的代码,我为两个可用区使用了两个挂载点:
resource "aws_efs_file_system" "efs_apache" {
}
resource "aws_efs_mount_target" "efs-mount" {
count = 2
file_system_id = aws_efs_file_system.efs_apache.id
subnet_id = sort(var.subnet_ids)[count.index]
security_groups = [aws_security_group.efs.id]
}
resource "aws_efs_access_point" "efs-access-point" {
file_system_id = aws_efs_file_system.efs_apache.id
}
resource "aws_security_group" "efs" {
name = "${var.name}-efs-sg"
description = "Allow traffic from self"
vpc_id …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform amazon-efs aws-fargate terraform-provider-aws
我正在尝试从 terraform 0.12 升级到 0.13。
当我运行时,它似乎没有任何特定的语法问题terraform 0.13upgrade。
只version.tf添加了一个文件
+terraform {
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ }
+ }
+ required_version = ">= 0.13"
+}
Run Code Online (Sandbox Code Playgroud)
当我跑步时,terraform plan我得到了
Error: Could not load plugin
Plugin reinitialization required. Please run "terraform init".
Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Terraform 中创建一个模块,以在 Kubernetes 集群中创建基本资源,这意味着一个cert-manager, ingress-nginx(作为入口控制器)和一个ClusterIssuer用于证书。按照这个确切的顺序。
前两个我使用helm_release资源和cluster_issuervia进行安装kubernetes_manifest。
我收到以下错误,经过一些 Google 搜索后,我发现这是因为cert-manager安装了所需的 CRD ,ClusterIssuer但在这个terraform plan阶段,由于它们尚未安装,清单无法检测到ClusterIssuer.
然后,我想知道是否有一种方法可以绕过这个问题,但仍然可以在相同的配置中仅使用一个来创建所有内容terraform apply?
注意:我尝试使用 dependent_on 参数并包含一个time_sleep块,但它没有用,因为计划中没有安装任何内容,这就是它失败的地方
| Error: Failed to determine GroupVersionResource for manifest\n\xe2\x94\x82 \n\xe2\x94\x82 with module.k8s_base.kubernetes_manifest.cluster_issuer,\n\xe2\x94\x82 on ../../modules/k8s_base/main.tf line 37, in resource "kubernetes_manifest" "cluster_issuer":\n\xe2\x94\x82 37: resource "kubernetes_manifest" "cluster_issuer" {\n\xe2\x94\x82 \n\xe2\x94\x82 no matches for kind "ClusterIssuer" in group "cert-manager.io"\nRun Code Online (Sandbox Code Playgroud)\n … 错误:配置 Terraform AWS 提供商时出错:
验证提供程序凭据时出错:调用 sts:GetCallerIdentity 时出错:操作错误 STS:GetCallerIdentity,https 响应错误 StatusCode:403,RequestID:95e52463-8cd7-038-b924-3a5d4ad6ef03,api 错误 InvalidClientTokenId:请求中包含的安全令牌无效。与提供者[“registry.terraform.io/hashicorp/aws”],在provider.tf第1行,在提供者“aws”中:1:提供者“aws”{
我只有两个文件。
resource "aws_instance" "web" {
ami = "ami-068257025f72f470d"
instance_type = "t2.micro"
tags = {
Name = "instance_using_terraform"
}
}
Run Code Online (Sandbox Code Playgroud)
provider "aws" {
region = "ap-east-1"
access_key = "xxxx"
secret_key = "xxxx/xxx+xxx"
}
Run Code Online (Sandbox Code Playgroud)
amazon-ec2 amazon-web-services terraform terraform-provider-aws
我已经使用 Terraform 创建了一个存储帐户。我想禁用在 Azure 门户中的存储帐户设置和配置下找到的名为“允许公共 blob 访问”的选项,但是在azurerm_storage_account命令下,我似乎找不到实现此目的所需的选项。
下面是我到目前为止创建存储帐户的代码,它可以工作,但如果有人能指出我正确的方向,那就太好了,谢谢。
存储账户
resource "azurerm_storage_account" "st" {
name = var.st.name
resource_group_name = var.rg_shared_name
location = var.rg_shared_location
account_tier = var.st.tier
account_replication_type = var.st.replication
public_network_access_enabled = false
}
Run Code Online (Sandbox Code Playgroud) terraform ×10
amazon-ec2 ×1
amazon-efs ×1
amazon-iam ×1
aws-fargate ×1
aws-lambda ×1
azure ×1
kubernetes ×1
terragrunt ×1