我希望我的 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) 我在 GCP 上设置了一个带有远程后端的 terraform 项目。现在,当我想要部署基础设施时,我遇到了凭据问题。我有一个凭据文件
\home\mike\.config\gcloud\credentials.json
Run Code Online (Sandbox Code Playgroud)
在我的 terraform 项目中,我有以下涉及远程状态的数据:
data "terraform_remote_state" "project_id" {
backend = "gcs"
workspace = "${terraform.workspace}"
config {
bucket = "${var.bucket_name}"
prefix = "${var.prefix_project}"
}
}
Run Code Online (Sandbox Code Playgroud)
我用我的凭据文件的详细信息指定云提供商。
provider "google" {
version = "~> 1.16"
project = "${data.terraform_remote_state.project_id.project_id}"
region = "${var.region}"
credentials = "${file(var.credentials)}"
}
Run Code Online (Sandbox Code Playgroud)
然而,这会遇到
data.terraform_remote_state.project_id: data.terraform_remote_state.project_id:
error initializing backend:
storage.NewClient() failed: dialing: google: could not find default
credentials.
Run Code Online (Sandbox Code Playgroud)
如果我添加
export GOOGLE_APPLICATION_CREDENTIALS=/home/mike/.config/gcloud/credentials.json
Run Code Online (Sandbox Code Playgroud)
我确实让它按预期运行。我的问题是,我想在 terraform 文件中指定凭据,因为我从无法设置环境变量的 python 脚本中以自动方式运行 terraform 命令。如何在不设置环境变量的情况下让 terraform 知道凭据在哪里?
我正在尝试使用 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 脚本时,我们会遇到以下问题:
错误刷新状态:S3 中的状态数据没有预期的内容。这可能是由于 S3 处理先前状态更新的异常长时间延迟造成的。请等待一两分钟,然后重试。如果此问题仍然存在,并且 S3 和 DynamoDB 都没有遇到中断,您可能需要手动验证远程状态并将存储在 DynamoDB 表中的 Digest 值更新为以下值
有没有其他方法可以直接使用 terraform 启用这些规则,而无需在 GCP 中创建单独的防火墙规则,然后将标签附加到计算引擎
目前我正在这样做
resource "google_compute_firewall" "allow_http" {
name = "allow-http-rule"
network = "default"
allow {
ports = ["80"]
protocol = "tcp"
}
target_tags = ["allow-http"]
priority = 1000
}
Run Code Online (Sandbox Code Playgroud)
然后使用这个标签
resource "google_compute_instance" "app" {
...
tags = ["allow-http"]
}
Run Code Online (Sandbox Code Playgroud) google-compute-engine google-cloud-platform terraform terraform-provider-gcp
我正在实现一个安全组模块,以便它将通过获取和过滤 cidr 和 source_security_group_id 创建安全组规则来创建安全组规则。
当前模块配置。
resource "aws_security_group" "this" {
name = var.name
description = var.description
vpc_id = var.vpc_id
revoke_rules_on_delete = var.revoke_rules_on_delete
}
## CIDR Rule
resource "aws_security_group_rule" "cidr_rule" {
count = length(var.security_group_rules)
type = var.security_group_rules[count.index].type
from_port = var.security_group_rules[count.index].from_port
to_port = var.security_group_rules[count.index].to_port
protocol = var.security_group_rules[count.index].protocol
cidr_blocks = var.security_group_rules[count.index].cidr_block
description = var.security_group_rules[count.index].description
security_group_id = aws_security_group.this.id
}
## Source_security_group_id Rule
resource "aws_security_group_rule" "source_sg_id_rule" {
count = length(var.security_group_rules)
type = var.security_group_rules[count.index].type
from_port = var.security_group_rules[count.index].from_port
to_port = var.security_group_rules[count.index].to_port
protocol = var.security_group_rules[count.index].protocol
source_security_group_id = …Run Code Online (Sandbox Code Playgroud) terraform ×10
aws-lambda ×2
.net ×1
amazon-ecs ×1
amazon-elb ×1
asp.net-core ×1
azure ×1
hcl ×1
variables ×1