gpt4 book ai didi

openstack - 添加资源时 Terraform 身份验证不起作用

转载 作者:行者123 更新时间:2023-12-03 06:58:58 24 4
gpt4 key购买 nike

我想在我们的 OpenStack 环境中尝试 terraform。我尝试设置它,当仅定义以下内容时它似乎可以工作:

provider "openstack" {
user_name = "test"
tenant_name = "test"
password = "testpassword"
auth_url = "https://test:5000/v3/"
region = "test"
}

我可以运行 terraform plan,没有任何问题,它说:

No changes. Infrastructure is up-to-date. This means that Terraform did not detect any differences between your configuration and real physical resources that exist. As a result, no actions need to be performed.

当我尝试添加资源时:

resource "openstack_compute_instance_v2" "test" {
name = "test_server"
image_id = "test_id123"
flavor_id = "3"
key_pair = "test"
security_groups = ["default"]

network {
name = "Default Network"
}
}

当我运行 terraform plan 时,我现在得到

Error: Error running plan: 1 error(s) occurred: provider.openstack: Authentication failed

最佳答案

身份验证正在运行。您的 provider 部分中的某些内容不正确。

当没有资源使用provider信息时,Terraform不会验证该信息。

我验证了您的发现,然后更进一步。我使用您的示例创建了两个提供程序,一个用于 AWS,另一个用于 OpenStack。然后,我添加了一个资源来创建 AWS VPC。我的 AWS 凭证是正确的。当我运行 terraform plan 时,它返回了构建 VPC 的行动计划。它没有检查伪造的 OpenStack 凭证。

另一件事是,一旦提供者有了资源,即使没有什么可做的,它也总是使用凭据。

provider "aws" {
access_key = "<redacted>"
secret_key = "<redacted>"
region = "us-east-1"
}

provider "openstack" {
user_name = "test"
tenant_name = "test"
password = "testpassword"
auth_url = "https://test:5000/v3/"
region = "test"
}


/* Create VPC */
resource "aws_vpc" "default" {
cidr_block = "10.200.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags {
Name = "testing"
}
}

生成以下输出,验证未检查 OpenStack provider:

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

+ aws_vpc.default
id: <computed>
arn: <computed>
assign_generated_ipv6_cidr_block: "false"
cidr_block: "10.200.0.0/16"
default_network_acl_id: <computed>
default_route_table_id: <computed>
default_security_group_id: <computed>
dhcp_options_id: <computed>
enable_classiclink: <computed>
enable_classiclink_dns_support: <computed>
enable_dns_hostnames: "true"
enable_dns_support: "true"
provider "aws" {
instance_tenancy: "default"
ipv6_association_id: <computed>
ipv6_cidr_block: <computed>
main_route_table_id: <computed>
tags.%: "1"
tags.Name: "testing"


Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

关于openstack - 添加资源时 Terraform 身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52389887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com