如何为阿里云设置terraform语法上的region?

如何为阿里云设置terraform语法上的region?,terraform,alibaba-cloud,Terraform,Alibaba Cloud,来自terraform官方文件: Attributes Reference The following attributes are exported in addition to the arguments listed above: regions - A list of regions. Each element contains the following attributes: id - ID of the region. local_name - Name of

来自terraform官方文件:

Attributes Reference
The following attributes are exported in addition to the arguments 
listed above:
regions - A list of regions. Each element contains the following 
   attributes:
   id - ID of the region.
   local_name - Name of the region in the local language.
语法如下:

value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
我的第一个问题是我在哪里可以得到我的本地名字

我想我在阿里云文档中找不到

第二个问题是在哪里放置区域id

value = "${data.alicloud_regions.current_region_ds.regions.ap-southeast-5.mylocal_name}"

根据你应该坚持的原则

您不一定需要提供区域ID本身。查看一个仅输入可用性区域ID的示例

关于如何设置阿里云资源的代码,还有很多其他有用的例子


如果您需要更具体的答案,请告诉我们您想要实现什么。

您需要在配置阿里云提供商时设置您的区域

provider "alicloud" {
  access_key = "${var.accesskey}"
  secret_key = "${var.secretkey}"
  region     = "${var.region}"
}
注意:阿里云提供了几种输入凭据进行身份验证的方式。它们是静态和动态的。为了使用静态方法进行身份验证,必须在凭据中列出区域ID,但如果使用动态方法,则可以从阿里云\u区域环境变量中获取

现在,回答你的问题

1) 最初,您在配置中指定了区域。您将通过以下方式获得配置的区域

data "alicloud_regions" "current_region_ds" {
  current = true
}

output "current_region_id" {
  value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
} 
使用
current=true
时,它将返回当前区域,否则必须使用name=region参数手动定义

value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
它将给出指定区域的id。如果要使用本地名称而不是id,请将
id
更改为
local\u name

value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
注意:最好使用
id
而不是
local\u name

value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
2) 您指定的两种方式都是错误的。您已经在配置中指定了您刚刚访问的区域

比如说,

data "alicloud_regions" "current_region_ds" {
      name="cn-beijing"
    }
然后访问它

value = "${data.alicloud_regions.current_region_ds.regions.0.id}"