我目前正在使用Terraform设置 AWS CloudWatch Alarm 来检测服务器的运行状况。使用 AWS Route 53 运行状况检查检查运行状况。我的.tf文件是:
resource "aws_cloudwatch_metric_alarm" "val1-alarm" {
alarm_name = "val-alarm"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "HealthCheckStatus"
namespace = "AWS/Route53"
period = "60"
statistic = "Minimum"
threshold = "0"
dimensions {
HealthCheckId = "${aws_route53_health_check.val1-hc.id}"
}
alarm_description = "This metric monitor whether the server is down or not."
insufficient_data_actions = []
}
resource "aws_route53_health_check" "val1-hc" {
fqdn = "${aws_route53_record.val1-record.name}"
port = 27017
type = "TCP"
failure_threshold = "3"
request_interval = …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-cloudwatch amazon-route53 terraform
我正在使用 Terraform 设置远程后端来管理状态。I\xe2\x80\x99ve 设置了一个 connection.tf 文件,用于连接和声明 Terraform 状态文件的 GCS。文件内容如下所示。
\n\nprovider "google" {\n credentials = "${file("../../secrets/account-thrashingcode.json")}"\n project = "thrashingcorecode"\n region = "us-west1"\n}\n\nterraform {\n backend "gcs" {\n bucket = "terraform-remote-states"\n path = "dev/terraform.tfstate"\n project = "thrashingcorecode"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n资源 I\xe2\x80\x99ve 设置(至少对于本示例而言)是在 GCP 中创建默认网络的超级简单配置。该配置看起来像这样。
\n\ndata "google_compute_network" "my-network" {\n name = "default-us-west1"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n现在,当我运行 terraform init 时,出现此错误。
\n\n$ terraform init\n\nInitializing the backend...\n\nSuccessfully configured the backend "gcs"! Terraform will automatically\nuse this backend unless the backend configuration changes.\nError refreshing state: [WARN] Error retrieving …Run Code Online (Sandbox Code Playgroud) 我正在编写一个 terraform 模块,该模块提供 RDS 数据库实例及其用于控制入站连接的关联安全组。我遇到的问题是安全组资源需要数据库端口作为参数,而数据库实例资源需要安全组 ID 作为参数。因此出现循环错误。
resource "aws_security_group" "this" {
name = "${local.name}-inbound"
description = "Allow inbound traffic from customer instances and management"
vpc_id = "${var.vpc_id}"
ingress {
from_port = "${aws_db_instance.this.port}"
to_port = "${aws_db_instance.this.port}"
protocol = 6
security_groups = ["${var.ingress_sg_ids}"]
}
}
resource "aws_db_instance" "this" {
allocated_storage = "${var.storage_size}"
storage_type = "${var.storage_type}"
engine = "${var.db_engine}"
engine_version = "${var.db_engine_version}"
instance_class = "${var.instance_type}"
identifier_prefix = "${local.name}-"
name = "${var.env}_${var.workspace}"
username = "${var.root_username}"
password = "${random_id.root_password.b64}"
db_subnet_group_name = "${aws_db_subnet_group.this.name}"
parameter_group_name = "${var.param_group_name}" …Run Code Online (Sandbox Code Playgroud) 我正在使用 Terraform 配置 AWS CodeBuild。在环境部分,我配置了以下内容:
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:3.0"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "CODEBUILD"
environment_variable {
name = "SOME_KEY1"
value = "SOME_VALUE1"
}
environment_variable {
name = "SOME_KEY2"
value = "SOME_VALUE2"
}
}
Run Code Online (Sandbox Code Playgroud)
我的 Codebuild 项目中有 20 多个环境变量需要配置。
是否可以创建一个列表并定义一个 environment_variable 参数来配置所有环境变量?
amazon-web-services terraform aws-codebuild terraform-provider-aws
Terraform 中是否有 if else 选择?Azure 门户中已经手动配置了许多资源。有没有办法通过在 Terraform 中的 if else select 语句来检测资源,以便如果资源退出,那么我将其用作数据,否则创建资源。
当我尝试使用 terraform 创建子网时,我不断收到以下错误。使用 aws 控制台创建子网没有问题。有人可以帮助我吗?
Error: error creating subnet: InvalidSubnet.Range: The CIDR '192.168.1.0/24' is invalid.
status code: 400
Run Code Online (Sandbox Code Playgroud)
创建 VPC 的代码:
resource "aws_vpc" "vpc_worker" {
provider = aws.region-worker
cidr_block = "198.168.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "master-vpc-jenkins"
}
}
Run Code Online (Sandbox Code Playgroud)
创建子网的代码:
#Create subnet in us-west-2
resource "aws_subnet" "subnet_1_worker" {
provider = aws.region-worker
vpc_id = aws_vpc.vpc_worker.id
cidr_block = "192.168.1.0/24"
}
Run Code Online (Sandbox Code Playgroud)
地形版本:0.12.29
提前致谢。
amazon-web-services terraform terraform-provider-aws terraform0.12+
当我terraform init在 Apple Silicon macbook pro 上运行我的 Google Cloud Platform 项目时,出现此错误。
Provider registry.terraform.io/hashicorp/google v3.57.0 does not have a package available for your current platform, darwin_arm64.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我以为 Rosetta2 模拟器会选中这个框,但唉...
开始时我使用的是默认工作区。由于复杂性增加,我想使用多个工作区。我想将默认工作区中的内容移动到其自己的工作区中或将默认工作区重命名为另一个工作区。我怎样才能做到这一点?
我有一个为 GKE 集群设置节点池名称的代码片段,它非常不可读。我将不胜感激任何帮助使其更像样和更容易理解正在发生的事情。
output "test" {
value = regex("(?:[a-z](?:[-a-z0-9]{0,38}[a-z0-9])?)", lower(var.node_pool_version != "" ? var.node_pool_name != "" ? "${var.node_pool_name}-v${replace("${var.node_pool_version}",".","-")}" : "${var.name_prefix}-v${replace("${var.node_pool_version}",".","-")}" : var.node_pool_name != "" ? var.node_pool_name : "${var.name_prefix}-standard"))
}
variable "node_pool_version" {
description = "Override node_version for cluster upgrades"
type = string
default = ""
}
variable "node_pool_name" {
type = string
default = ""
}
variable "name_prefix" {
type = string
default = "develop"
}
Run Code Online (Sandbox Code Playgroud)
输出:
? terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs: …Run Code Online (Sandbox Code Playgroud) 我正在尝试遍历地图并在aws_codebuild_project. 这是我第一次在 Terraform 中使用循环。我的主要困惑来源是我不知道资源是否必须“支持”循环,或者是否可以在资源内的几乎所有地方进行迭代?
variable "custom_environment_variables" {
type = map(any)
default = {}
}
resource "aws_codebuild_project" "my_project" {
# other props...
environment {
type = "LINUX_CONTAINER"
# more props
# some hardcoded environment_variable
environment_variable {
name = "APP_STAGE"
value = var.app_stage
}
# some dynamic environment_variable
dynamic "custom_environment_variable" {
for_each = var.custom_environment_variables
environment_variable {
name = custom_environment_variable.key
value = custom_environment_variable.value
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此代码导致此错误:
? Error: Unsupported block type
?
? on ../modules/static_web_pipeline/main.tf line 155, in resource …Run Code Online (Sandbox Code Playgroud)