使用terraform 0.9.3创建AWS Lambda函数时,我无法加入我选择的VPC.
这是我的函数的样子:
resource "aws_lambda_function" "lambda_function" {
s3_bucket = "${var.s3_bucket}"
s3_key = "${var.s3_key}"
function_name = "${var.function_name}"
role = "${var.role_arn}"
handler = "${var.handler}"
runtime = "${var.runtime}"
timeout = "30"
memory_size = 256
publish = true
vpc_config {
subnet_ids = ["${var.subnet_ids}"]
security_group_ids = ["${var.security_group_ids}"]
}
}
Run Code Online (Sandbox Code Playgroud)
我用于角色的政策是
data "aws_iam_policy_document" "lambda-policy_policy_document" {
statement {
effect = "Allow"
actions = [
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
]
resources = ["*"]
}
}
Run Code Online (Sandbox Code Playgroud)
资源创建得很好,如果我尝试通过AWS控制台添加VPC和子网,那一切都可以解决.
更新(创建计划):
module.******.aws_lambda_function.lambda_function
arn: "<computed>"
environment.#: "1" …Run Code Online (Sandbox Code Playgroud) 我的TF代码给了我一个错误:
/*
* Policy: AmazonEC2ReadOnlyAccess
*/
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "elasticloadbalancing:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"cloudwatch:ListMetrics",
"cloudwatch:GetMetricStatistics",
"cloudwatch:Describe*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "autoscaling:Describe*",
"Resource": "*"
}
]
}
EOF
Run Code Online (Sandbox Code Playgroud)
我从https://console.aws.amazon.com/iam/home?region=us-west-2#/policies/arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess $ jsonEditor 复制并粘贴了该政策.
* aws_iam_role.<role name>: Error creating IAM Role <role name>: MalformedPolicyDocument: Has prohibited field Resource
status code: 400, request id: <request id>
Run Code Online (Sandbox Code Playgroud)
不知道为什么说资源被禁止.
我希望我的 lambda 调用 API,这需要一个 API 令牌。我想将 API 令牌放入 lambda 环境变量中。我怎样才能让 terraform 做到这一点?还是我以错误的方式接近这个?
长话短说,我不想将任务的 ECS 任务定义修订号硬编码到我的 lambda 源代码中。每次我有更新的任务定义时,基本上都在费力地更新我的源代码。在ECS 的 boto3 文档中run_task(),它明确指出
taskDefinition (string) -- [必需]
要运行的任务定义的系列和修订 (family:revision ) 或完整 ARN。如果未指定修订版,则使用最新的 ACTIVE 修订版。
但是,我发现如果我taskDefinition在client.run_task()没有特定修订号的情况下定义参数,则会出现权限错误:
调用 RunTask 操作时发生错误 (AccessDeniedException):用户:arn:aws:sts::MY_ACCOUNT_ID:assumed-role/my-lambda-role/trigger-ecs-task is notauthorized to perform: ecs:RunTask on resource: arn:aws:ecs:MY_REGION:MY_ACCOUNT_ID:task-definition/an-important-task
如果我将定义切换为an-important-task:LATESTor an-important-task:*,则会出现另一个错误:
...无权执行:ecs:RunTask on resource: *
这很奇怪,因为它看起来与文档说明的相反 - 当我包含一个修订号时,比如an-important-task:5,lambda 会完美地触发。在我的 lambda 函数中,我只是调用了我的 ECS 任务:
def lambda_handler(event, context):
client = boto3.client('ecs')
print("Running task.")
response = client.run_task(
cluster='my-cluster',
launchType='FARGATE',
taskDefinition='an-important-task', # <-- notice no revision number …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Terraform 部署 Cloudfront 发行版,但在指定 origin_id 时出现错误
Cloudfront 通过 Route53 查找指向负载均衡器。
resource "aws_cloudfront_distribution" "my-app" {
origin {
custom_origin_config {
http_port = 443
https_port = 443
origin_protocol_policy = "https-only"
origin_ssl_protocols = ["TLSv1.2"]
}
domain_name = "${var.domain_name}"
origin_id = "Custom-${var.domain_name}"
}
...
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "DELETE"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${local.origin_id}"
...
Run Code Online (Sandbox Code Playgroud)
其中var.domain_name是 route53 记录,local.origin_id是唯一 ID。
执行 terraform apply 时,出现此错误:
aws_cloudfront_distribution.my-app: error creating CloudFront Distribution: NoSuchOrigin: One or more …
我正在使用 Terraform proparar。在一种情况下,我需要执行“local-exec”配置并将命令的输出 [这是 IP 地址数组] 用于下一个“远程执行”配置。
而且我无法将“local-exec”临时输出存储在本地变量中以供以后使用。我可以将它存储在本地文件中,但不能存储在中间变量中
count = "${length(data.local_file.instance_ips.content)}"
Run Code Online (Sandbox Code Playgroud)
这是行不通的。
resource "null_resource" "get-instance-ip-41" {
provisioner "local-exec" {
command = "${path.module}\\scripts\\findprivateip.bat > ${data.template_file.PrivateIpAddress.rendered}"
}
}
data "template_file" "PrivateIpAddress" {
template = "/output.log"
}
data "local_file" "instance_ips" {
filename = "${data.template_file.PrivateIpAddress.rendered}"
depends_on = ["null_resource.get-instance-ip-41"]
}
output "IP-address" {
value = "${data.local_file.instance_ips.content}"
}
# ---------------------------------------------------------------------------------------------------------------------
# Update the instnaces by installing newrelic agent using remote-exec
# ---------------------------------------------------------------------------------------------------------------------
resource "null_resource" "copy_file_newrelic_v_29" {
depends_on = ["null_resource.get-instance-ip-41"]
count = "${length(data.local_file.instance_ips.content)}"
triggers = {
cluster_instance_id …Run Code Online (Sandbox Code Playgroud) 开箱即用,我认为azurerm_app_service provider 确实允许我们通过使用该dotnet_framework_version字段来指定 .Net 框架版本。
dotnet_framework_version -(可选)此应用服务中使用的 .net 框架的 CLR 版本。可能的值是 v2.0(它将使用 .net CLR v2 的最新版本的 .net 框架 - 当前是 .net 3.5)和 v4.0(对应于 .net CLR v4 的最新版本 - 在写作时间是 .net 4.7.1)。有关基于您所针对的 .net 框架使用哪个 .net CLR 版本的更多信息 - 请参阅此表。默认为 v4.0。
https://www.terraform.io/docs/providers/azurerm/r/app_service.html#dotnet_framework_version
该文档说可能的值为 v2.0 或 v4.0。
但是如果我的目标是 .NET Core,而是说 v2.2 呢?我应该在这里做什么?
Azure 门户允许从下拉菜单中选择 .NET Core。(见下面的截图)
我不确定 Terraform azurerm_app_service 是否也有办法做到这一点。
如果有一种方法可以在 Terraform 创建 aws_lb 时获取 aws_lb 资源的分配 IP 地址?
如AWS 文档 - NLB - 要找到要列入白名单的私有 IP 地址,我们可以找出与 ELB 关联的 IP 地址。
为了能够设置安全组以将 ELB IP 地址列入白名单,因为网络负载均衡器不能没有安全组,因为网络负载均衡器没有安全组。
考虑过aws_network_interface但它不会出现错误。
错误:找不到匹配的网络接口
另外我认为 datasource 假设资源已经存在并且不能用于 Terraform 创建的资源。
我正在使用terraform在azure中预配置一些资源,但似乎无法掌控安装nginx-ingress,因为它等待状态超时
helm_release.nginx_ingress:发生1个错误:
helm_release.nginx_ingress:rpc错误:代码=未知desc =发布nginx-ingress失败:等待条件超时
面对错误,Terraform不会自动回滚。相反,您的Terraform状态文件已使用成功完成的所有资源进行了部分更新。请解决以上错误,然后再次应用以逐步更改您的基础架构。主文件
data "azurerm_public_ip" "nginx_ingress" {
name = "xxxx-public-ip"
resource_group_name = "xxxx-public-ip"
}
resource "azurerm_resource_group" "xxxx_RG" {
name = "${var.name_prefix}"
location = "${var.location}"
}
resource "azurerm_kubernetes_cluster" "k8s" {
name = "${var.name_prefix}-aks"
kubernetes_version = "${var.kubernetes_version}"
location = "${azurerm_resource_group.xxxx_RG.location}"
resource_group_name = "${azurerm_resource_group.xxxx_RG.name}"
dns_prefix = "AKS-${var.dns_prefix}"
agent_pool_profile {
name = "${var.node_pool_name}"
count = "${var.node_pool_size}"
vm_size = "${var.node_pool_vmsize}"
os_type = "${var.node_pool_os}"
os_disk_size_gb = 30
}
service_principal {
client_id = "${var.client_id}"
client_secret = "${var.client_secret}"
}
tags = {
environment = "${var.env_tag}"
} …Run Code Online (Sandbox Code Playgroud) terraform kubernetes-helm terraform-provider-azure azure-aks nginx-ingress
当我们尝试运行带有远程状态处理的 terraform 脚本时,我们会遇到以下问题:
错误刷新状态:S3 中的状态数据没有预期的内容。这可能是由于 S3 处理先前状态更新的异常长时间延迟造成的。请等待一两分钟,然后重试。如果此问题仍然存在,并且 S3 和 DynamoDB 都没有遇到中断,您可能需要手动验证远程状态并将存储在 DynamoDB 表中的 Digest 值更新为以下值
terraform ×10
aws-lambda ×3
.net ×1
amazon-ecs ×1
amazon-elb ×1
amazon-iam ×1
asp.net-core ×1
azure ×1
azure-aks ×1
variables ×1