Reputation: 755
From terraform official documentation :
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.
And the syntax is like this :
value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
My first question is where can I get my local_name?
I think I cannot find it from alibaba cloud documentation
And second question is where to place the region id?
value = "${data.alicloud_regions.current_region_ds.regions.ap-southeast-5.mylocal_name}"
or
value = "${data.alicloud_regions.current_region_ds.regions.mylocal_name.ap-southeast-5}"
Upvotes: 2
Views: 799
Reputation: 99
You need to set up your region while you are configuring the AliCloud Provider itself.
provider "alicloud" {
access_key = "${var.accesskey}"
secret_key = "${var.secretkey}"
region = "${var.region}"
}
Note: There are several ways provided by Alicloud to enter credentials to authenticate. They are static and dynamic. Region ID must be listed out in credentials in order to authenticate using the static method, but if we are using dynamic method it can be sourced from the ALICLOUD_REGION environment variables.
Now, To your Questions
1) Initially, You specified the region in configuration. You will get the region you configured by following
data "alicloud_regions" "current_region_ds" {
current = true
}
output "current_region_id" {
value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
}
When you use current = true
it will return the current region or else you have to define manually using name= region argument.
value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
It will give the id of the region specified. If you want to use local_name instead of id then change id
to local_name
.
value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
Note: It is better to use id
instead of local_name
.
2) Both ways you specified are wrong. You have specified the region in the configuration you are just accessing it.
For instance,
data "alicloud_regions" "current_region_ds" {
name="cn-beijing"
}
then to access it,
value = "${data.alicloud_regions.current_region_ds.regions.0.id}"
or
value = "${data.alicloud_regions.current_region_ds.regions.0.local_name}"
Upvotes: 1
Reputation: 340
According to the Terraform documentation you should stick to Alibaba Cloud Regions ID.
You don't necessarily need to provide the region ID itself. Take a look at a VPC Terraform sample where you enter just Availability Zone ID https://github.com/terraform-providers/terraform-provider-alicloud/blob/master/examples/vpc/variables.tf
variable "availability_zones" {
default = "cn-beijing-c"
}
There are many other useful examples with code how to setup Alibaba Cloud resources.
https://github.com/terraform-providers/terraform-provider-alicloud/tree/master/examples
If you need more specific answer tell us what are you trying to achieve.
Upvotes: 1