因此,通过 Terraform,我创建了一个 IAM 策略并将其附加到一个角色。我目前正在运行:
Terraform v0.12.16
provider.aws v2.40.0
provider.template v2.1.2
Run Code Online (Sandbox Code Playgroud)
执行代码时,我可以毫无问题地初始化 terraform。运行 terraform plan 时,出现以下错误:
Error: "policy" contains an invalid JSON: invalid character '}' looking for beginning of value
on ec2-iam.tf line 8, in resource "aws_iam_role_policy" "s3_ec2_policy":
8: resource "aws_iam_role_policy" "s3_ec2_policy" {
Run Code Online (Sandbox Code Playgroud)
我陷入了这个错误。任何意见将是有益的。下面是我的代码:
data "template_file" "s3_web_policy" {
template = file("scripts/iam/web-ec2-policy.json")
vars = {
s3_bucket_arn = "arn:aws:s3:::${var.my_app_s3_bucket}/*"
}
}
resource "aws_iam_role_policy" "s3_ec2_policy" {
name = "s3_ec2_policy"
role = aws_iam_role.s3_ec2_role.id
policy = data.template_file.s3_web_policy.rendered
}
resource "aws_iam_role" "s3_ec2_role" {
name = "s3_ec2_role"
assume_role_policy …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform terraform-template-file terraform-provider-aws
尝试使用目标组使用 IP 作为目标类型的现有 NLB 创建 ECS 服务时,获取目标类型ip,与桥接网络模式不兼容错误。
该错误来自 Terraform,因为它使用它来创建所有 AWS 资源。
错误:InvalidParameterException:提供的目标组 arn:aws:elasticloadbalancing:$REGION:$ACCOUNT:targetgroup ... 具有目标类型 ip,与任务定义中指定的桥接网络模式不兼容。
如果 Terraform(或其消息)正确的话, Terraform Github问题 #11719的TF_DEBUG输出似乎表明这是限制。
2020-01-22T20:04:46.819Z [DEBUG] plugin.terraform-provider-aws_v2.45.0_x4: 2020/01/22 20:04:46 [DEBUG] [aws-sdk-go] {"__type":"InvalidParameterException","message":"The provided target group arn:aws:elasticloadbalancing:us-east-1:xxx:targetgroup/llprd20200122052638603300000006/a0a2d775807f6620 has target type ip, which is incompatible with the bridge network mode specified in the task definition."}
Run Code Online (Sandbox Code Playgroud)
请告知这是否是 AWS 的限制。据我到目前为止查看的AWS文档,没有任何信息表明IP目标类型不能用于桥接网络模式。不过,想百分百确定。
- 对于目标类型,选择是否使用实例 ID 或 IP 地址注册目标。
重要
如果您的服务的任务定义使用 awsvpc 网络模式(Fargate 启动类型需要该模式),您必须选择 ip 作为目标类型,而不是实例。这是因为使用 awsvpc 网络模式的任务与弹性网络接口关联,而不是与 Amazon EC2 实例关联。 …
我有下面的 terraform 模板,它创建用户、访问密钥并存储在秘密管理器中。
resource "aws_iam_user" "test" {
name = "test"
}
resource "aws_iam_access_key" "test" {
user = aws_iam_user.test.name
}
resource "aws_secretsmanager_secret" "test" {
name = "credentials"
description = "My credentials"
}
resource "aws_secretsmanager_secret_version" "test" {
secret_id = "${aws_secretsmanager_secret.test.id}"
secret_string = "{\"AccessKey\": data.aws_iam_access_key.test.id,\"SecretAccessKey\": data.aws_iam_access_key.test.secret}"
}
Run Code Online (Sandbox Code Playgroud)
Secret_string 中的值未设置。这是正确的用法吗?请帮助我设置正确的值
secret_string = "{\"AccessKey\": data.aws_iam_access_key.test.id,\"SecretAccessKey\": data.aws_iam_access_key.test.secret}"
Run Code Online (Sandbox Code Playgroud) 我正在尝试将文件从s3存储桶下载到我正在运行的服务器terraform,这可能吗?我尝试了下面的代码
data "aws_s3_bucket_objects" "my_objects" {
bucket = "examplebucket"
}
data "aws_s3_bucket_object" "object_info" {
key = "${element(data.aws_s3_bucket_objects.my_objects.keys, count.index)}"
bucket = "${data.aws_s3_bucket_objects.my_objects.bucket}"
}
provisioner "local-exec" {
content = "${data.aws_s3_bucket_object.object_info.body}"
}
Run Code Online (Sandbox Code Playgroud)
当我运行时terraform plan出现以下错误
Error: Unsupported block type
on s3.tf line 11:
11: provisioner "local-exec" {
Blocks of type "provisioner" are not expected here.
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?对此的任何帮助将不胜感激。
\xe2\x9e\x9c terraform -v \nTerraform v0.12.24\n+ provider.aws v2.60.0\n\nRun Code Online (Sandbox Code Playgroud)\n\n我的地形example.tf:
\n\nlocals {\n standard_tags = {\n team = var.team\n project = var.project\n component = var.component\n environment = var.environment\n }\n}\n\nprovider "aws" {\n profile = "profile"\n region = var.region\n}\n\nresource "aws_key_pair" "security_key" {\n key_name = "security_key"\n public_key = file(".ssh/key.pub")\n}\n\n# New resource for the S3 bucket our application will use.\nresource "aws_s3_bucket" "project_bucket" {\n # NOTE: S3 bucket names must be unique across _all_ AWS accounts, so\n # this name must be changed before …Run Code Online (Sandbox Code Playgroud) 我在 AWS 上运行,并且有 VPC-A 和 VPC-B 我在两个 VPC 之间有一个 VPC 对等互连
我想要允许从 VPC-B 中的 SecurityGroupB 到 VPC-A 中的 SecurityGroupA 的流量
到目前为止,我通过以下调用使用 ruby 客户端完成了此操作
security_group_a.authorize_ingress(
ip_permissions: [
{
from_port: "-1",
ip_protocol: "-1",
to_port: "-1",
user_id_group_pairs: [
{
description: "Accept all traffic from SecurityGroupB",
group_id: security_group_b.id,
vpc_id: vpc_b.id,
vpc_peering_connection_id: peering_connection_id,
},
],
},
]
)
Run Code Online (Sandbox Code Playgroud)
我查看了 terraform 的aws_security_group_rule但找不到与上述设置等效的任何内容。
当我尝试将安全组 B 放入安全组 AI 的入口时,出现以下错误:
Error: Error authorizing security group rule type ingress: InvalidGroup.NotFound: You have specified two resources that belong to …Run Code Online (Sandbox Code Playgroud) amazon-vpc terraform aws-security-group terraform-provider-aws
此处的文档: https: //www.terraform.io/docs/providers/aws/r/default_route_table.html声称您可以使用 VPC id 导入默认路由表。
当我尝试这样做时,出现以下错误:
$ terraform import 'aws_default_route_table.aws-vpc' vpc-12345678
Error: resource aws_default_route_table doesn't support import
Run Code Online (Sandbox Code Playgroud)
我尝试使用路由表 ID 本身,以防文档不准确,但我得到了相同的错误。
我成功导入了路由表所属的VPC,并再次尝试导入路由表,但没有成功。
对于上下文 - 我需要导入默认路由表的原因是为 VPN 网关启用路由传播,如下所示:
resource aws_default_route_table aws-vpc {
default_route_table_id = var.aws_default_route_table_id
route {
cidr_block = "0.0.0.0/0"
gateway_id = var.aws_internet_gateway_id
}
propagating_vgws = [
aws_vpn_gateway.aws-vpn-gw.id
]
}
Run Code Online (Sandbox Code Playgroud)
我是否遗漏了一些东西,或者真的不可能将现有的默认路由表导入到 terraform 中?
我试图通过云初始化将文件复制到 Windows EC2 实例,方法是传递用户数据,云初始化模板运行,它创建一个文件夹但不复制文件,您能帮助我理解我在代码中做错了什么吗?
此代码通过自动缩放组的启动配置传递
data template_cloudinit_config ebs_snapshot_scripts {
gzip = false
base64_encode = false
part {
content_type = "text/cloud-config"
content = <<EOF
<powershell>
$path = "C:\aws"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
</powershell>
write_files:
- content: |
${file("${path.module}/../../../../scripts/aws-ebs-snapshot-ps/1-start-ebs-snapshot.ps1")}
path: C:\aws\1-start-ebs-snapshot.ps1
permissions: '0744'
- content: |
${file("${path.module}/../../../../scripts/aws-ebs-snapshot-ps/2-run-backup.cmd")}
path: C:\aws\2-run-backup.cmd
permissions: '0744'
- content: |
${file("${path.module}/../../../../scripts/aws-ebs-snapshot-ps/3-ebs-snapshot.ps1")}
path: C:\aws\3-ebs-snapshot.ps1
permissions: '0744'
EOF
}
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services cloud-init terraform terraform-provider-aws
我在 aws 证书管理器中有证书。
如何将此证书连接到aws_alb_listenerterraform?
现在我从计算机中的文件中获取证书。
resource "aws_alb_listener" "alb_front_https" {
load_balancer_arn = "${aws_alb.demo_eu_alb.arn}"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS-1-2-Ext-2018-06"
certificate_arn = "${aws_iam_server_certificate.lb_cert.arn}"
default_action {
target_group_arn = "${aws_alb_target_group.nginx.arn}"
type = "forward"
}
}
resource "aws_iam_server_certificate" "lb_cert" {
name = "lb_cert-${var.app}"
certificate_body = "${file("./www.xxx.com/cert.pem")}"
private_key = "${file("./www.xxx.com/privkey.pem")}"
certificate_chain = "${file("./www.xxx.com/chain.pem")}"
}
Run Code Online (Sandbox Code Playgroud)
我想aws_alb_listener在 aws 证书管理器上使用证书。
如何在地形中做到这一点?
我\xe2\x80\x99m 完成本教程并设法将一切设置正常。
\n\n在对计划进行排队时,我收到以下与变量相关的错误,但无法深入了解它。
\n有人对如何推进此事有任何想法吗?谢谢
\n希望这将是一个很容易启动和运行的过程!
\nConfiguring remote state backend...\nInitializing Terraform configuration...\n\nWarning: Value for undeclared variable\n\nThe root module does not declare a variable named "tag_user_name" but a value\nwas found in file "/terraform/terraform.tfvars". To use this value, add a\n"variable" block to the configuration.\n\nUsing a variables file to set an undeclared variable is deprecated and will\nbecome an error in a future release. If you wish to provide certain "global"\nsettings to all configurations in your organization, use TF_VAR_...\nenvironment …Run Code Online (Sandbox Code Playgroud)