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}"