我需要帮助每周安排 ec2 卷快照,并且需要使用 terraform aws 的云监视规则存档\删除超过 1 个月的备份。
请指导我使用 terraform 编写云监视规则。
问候, 公羊
terraform terraform-template-file terraform-provider-azure terraform-provider-aws terraform-provider-gcp
我正在尝试使用 GCP 在我的项目网络和另一个项目之间配置 VPC 对等互连,但是我不能,因为我无权列出另一个项目上的网络。
resource "google_compute_network" "my-network" {
name = "foobar"
auto_create_subnetworks = "false"
}
resource "google_compute_network_peering" "my-network" {
name = "peering1"
network = "${google_compute_network.my-network.self_link}"
peer_network = "${data.google_compute_network.another-network.self_link}"
}
data "google_compute_network" "another-network" {
name = "another"
project = "another-project"
}
Run Code Online (Sandbox Code Playgroud)
错误:
Error 403: Required 'compute.networks.get' permission for 'projects/another-project/global/networks/another', forbidden
Run Code Online (Sandbox Code Playgroud)
由于 terraform 无法访问,another-project我想知道是否有其他方法可以使用 terraform 执行此操作。
先感谢您!:)
我正在尝试roles/logging.logWriter使用 Terraform创建一个具有IAM 角色的基本服务帐户。下面是我如何配置这个:
resource "google_service_account" "log_user" {
account_id = "log-user"
display_name = "Logging User"
}
data "google_iam_policy" "log_policy" {
binding {
role = "roles/logging.logWriter"
members = [
"serviceAccount:${google_service_account.log_user.email}"
]
}
}
resource "google_service_account_iam_policy" "log_user_policy" {
service_account_id = "${google_service_account.log_user.name}"
policy_data = "${data.google_iam_policy.log_policy.policy_data}"
}
Run Code Online (Sandbox Code Playgroud)
运行时,terraform apply我收到以下错误消息:
* module.iam.google_service_account_iam_policy.log_user_policy: 1 error(s) occurred:
* google_service_account_iam_policy.log_user_policy: Error setting IAM policy for service account 'projects/arcadia-apps-237918/serviceAccounts/log-user@arcadia-apps-237918.iam.gserviceaccount.com': googleapi: Error 400: Role roles/logging.logWriter is not supported for this resource., badRequest
Run Code Online (Sandbox Code Playgroud)
从我所做的挖掘中,我似乎无法找到关于如何创建服务帐户然后为其附加角色的明确解释。
我正在尝试将以下ConfigMapyaml 文件(此处链接)转换为 a,kubernetes_config_map但在尝试定义它时遇到语法错误。
特别是,我无法绕过文件内的点opentsdb.conf符号
apiVersion: v1
kind: ConfigMap
metadata:
name: opentsdb-config
data:
opentsdb.conf: |
google.bigtable.project.id = REPLACE_WITH_PROJECT
google.bigtable.instance.id = REPLACE_WITH_INSTANCE
google.bigtable.zone.id = REPLACE_WITH_ZONE
hbase.client.connection.impl = com.google.cloud.bigtable.hbase1_2.BigtableConnection
google.bigtable.auth.service.account.enable = true
tsd.network.port = 4242
tsd.core.auto_create_metrics = true
tsd.core.meta.enable_realtime_ts = true
tsd.core.meta.enable_realtime_uid = true
tsd.core.meta.enable_tsuid_tracking = true
tsd.http.request.enable_chunked = true
tsd.http.request.max_chunk = 131072
tsd.storage.fix_duplicates = true
tsd.storage.enable_compaction = false
tsd.storage.max_tags = 12
tsd.http.staticroot = /opentsdb/build/staticroot
tsd.http.cachedir = /tmp/opentsdb
Run Code Online (Sandbox Code Playgroud)
这是我当前的尝试,但出现错误"opentsdb.conf"
resource "kubernetes_config_map" "opentsdb" {
metadata …Run Code Online (Sandbox Code Playgroud) 这是我的输入 json 文件:
{
"inputs": [
{
"acct_id": "foo-bar-15",
"display_name": "foo bar",
"project-role-pairs": {"test-1234": "roles/logging.logWriter", "test-2345": "roles/storage.objectViewer"}
},
{
"acct_id": "foo-bar-16",
"display_name": "john doe",
"project-role-pairs": {"test-3456": "roles/logging.logWriter", "test-4567": "roles/storage.objectViewer"}
}
]
}
Run Code Online (Sandbox Code Playgroud)
代码: 这是我的代码,根据输入在 GCP 中创建服务帐户(该部分工作正常)。它还尝试根据上面 json 文件中的 project-roles-pairs 映射在 2 个项目中创建 IAM 角色。我无法通过地图进行交互。我就是不知道为什么。目前的代码只是使用映射中的第一个键来表示两者,就好像没有第二对键值一样。我一直在寻找“扁平化”和动态块和集合产品。它们似乎不适合用例,或者我无法有效地使用它们。请帮忙。
locals {
json_data_7 = jsondecode(file("./data7.json"))
}
# Creates a Service Account for each top level in input
resource "google_service_account" "service_accounts_for_each_7" {
for_each = {for v in local.json_data_7.inputs: v.acct_id => v.display_name}
account_id = each.key
display_name = each.value …Run Code Online (Sandbox Code Playgroud) 我是地形世界的新手。我正在尝试在 GCP 项目上使用 terraformer,但始终找不到插件:
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --connect=true --
regions=europe-west1,europe-west4 --projects=myproj
2021/02/12 08:17:03 google importing project myproj region europe-west1
2021/02/12 08:17:04 google importing... gcs
2021/02/12 08:17:05 open \.terraform.d/plugins/windows_amd64: The system cannot find the path specified.
Run Code Online (Sandbox Code Playgroud)
在上述之前,安装了 terraformer:choco install terraformer我下载了 Google 提供程序 ,terraform-provider-google_v3.56.0_x5.exe将其放在我的 terraform 目录中,然后执行了terraform init。我检查了%AppData\Roaming\terraform.d\plugins\windows_amd64一下,发现它plugins\windows_amd64不存在,所以我创建了它,放入 Google exe 中并重新启动了 init。
我的 main.tf 是:
provider "google" {
project = "{myproj"
region = "europe-west2"
zone = "europe-west2-a"
}
Run Code Online (Sandbox Code Playgroud)
难道是巧克力安装导致了这个问题?我以前从未使用过它,但替代安装看起来令人生畏!
我目前有一个 terraform 对象声明如下:
locals {
x = {
a = [
{
p0 = "j"
p1 = "test-1"
p2 = 0
},
{
p0 = "k"
p1 = "test-2"
p2 = 0
}
]
b = [
{
p0 = "j"
p1 = "test-1"
p2 = 1
},
{
p0 = "k"
p1 = "test-3"
p2 = 0
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我想做的是压平结构,但我不知道这在地形中是否可行。就我而言,我知道 p0 在其自己的数组中将是唯一的,因此我应该能够为每个记录构造唯一的键。我想要的输出如下:
locals {
y = {
a-j {
p0 = "j"
p1 = "test-1"
p2 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加类型,但它没有选择它,boot_disk如果我将类型创建为对象,我很困惑如何给出“network_interface”类型。\n错误:\xe2\x94\x82 This default value is not compatible with the variable's type constraint: element "tags": string required.
variable worker {\n type = map(string)\n default = {\n worker_count = 2\n name = "k3s-master"\n machine_type = "n1-standard-1"\n tags = ["k3s", "k3s-master"]\n zone = "us-central1-a"\n\n\n boot_disk = {\n initialize_params = {\n image = "debian-9-stretch-v20200805"\n }\n }\n\n network_interface = {\n network = "default"\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n 我犯了一个似乎相当常见的错误,即使用google_service_account_iam_binding启用服务帐户来执行我应该使用的各种操作google_project_iam_binding。我现在一切正常,但我想了解google_service_account_iam_*资源的实际用途是什么?我真的找不到任何文档来解释您将在什么情况下使用它们。
对任何 beta 参数定义的任何 Google Cloud Platform (GCP) 资源进行地形改造都需要提供google-beta程序。是否应该google-beta使用提供者来代替或与提供者一起使用google提供程序一起使用?
换句话说,假设$GKE_CLUSTER_NAMEGCP 项目中存在某个 Google Kubernetes Engine (GKE) 集群$GCP_PROJECT_NAME某个 Google Kubernetes Engine (GKE) 集群:
gcloud container clusters list \\\n--format="value(name)" \\\n--project=$GCP_PROJECT_NAME\n\n#=>\n\n. . .\n$GKE_CLUSTER_NAME\n. . .\nRun Code Online (Sandbox Code Playgroud)\n启用配置连接器后:
\ngcloud container clusters describe $GKE_CLUSTER_NAME \\\n--format=\xe2\x80\x9cvalue(addonsConfig.configConnectorConfig.enabled)\xe2\x80\x9d \\\n--zone=$GKE_CLUSTER_ZONE\n\n#=>\n\nTrue\nRun Code Online (Sandbox Code Playgroud)\nTerraforming$GKE_CLUSTER_NAME需要一个google_container_cluster资源定义,container_cluster.tf其中包括config_connector_config参数(在addons_config块内;更多信息请参见此处)和provider参数(官方参考文档中缺少):
resource "google_container_cluster" "test" {\n addons_config {\n config_connector_config {\n enabled …Run Code Online (Sandbox Code Playgroud) google-cloud-platform google-kubernetes-engine terraform terraform-provider-gcp infrastructure-as-code