You can obtain the values of parameters that are defined in a template by querying the constraints of the parameters.
Background information
When you use AssociationProperty and AssociationPropertyMetadata to filter parameters, the filtered parameters may not meet your requirements in specific scenarios.
For example, the ZoneId parameter is used for multiple Alibaba Cloud services, but the values of the ZoneId parameter vary based on the Alibaba Cloud services. In this case, you can obtain the value of the ZoneId parameter defined in your template by querying the constraint of the ZoneId parameter.
Supported parameters
You can call the GetTemplateParameterConstraints operation instead of adding the relevant parameter to a template to query the values of parameters that are defined in the template.
The template whose parameter constraints you want to query must contain the Parameters
section.
The following table describes the parameters of which the constraints you can query.
Resource type | Parameter | Description |
ALIYUN::CS::KubernetesCluster |
| None |
ALIYUN::CS::ManagedKubernetesCluster |
| None |
ALIYUN::CS::ManagedEdgeKubernetesCluster |
| None |
ALIYUN::ECS::Instance |
| None |
ALIYUN::ECS::InstanceGroup |
| None |
ALIYUN::ECS::VSwitch |
| None |
ALIYUN::RDS::DBInstance |
| Note
|
ALIYUN::RDS::PrepayDBInstance |
| Note
|
ALIYUN::POLARDB::DBCluster |
| None |
ALIYUN::REDIS::Instance |
| None |
ALIYUN::REDIS::PrepayInstance |
| None |
ALIYUN::VPC::NatGateway |
| None |
ALIYUN::ADB::DBCluster |
| None |
ALIYUN::GPDB::DBInstance |
| None |
ALIYUN::GPDB::ElasticDBInstance |
| None |
ALIYUN::ALB::LoadBalancer |
| None |
ALIYUN::ElasticSearch::Instance |
| You can query specifications only by zone. |
ALIYUN::SLB::LoadBalancer |
| None |
ALIYUN::TSDB::HiTSDBInstance |
| None |
ALIYUN::DTS::SynchronizationJob |
| None |
ALIYUN::MONGODB::Instance |
| None |
ALIYUN::GA::BandwidthPackage |
| None |
ALIYUN::MONGODB::ServerlessInstance |
| None |
ALIYUN::RDS::DBInstanceClone |
| Note
|
ALIYUN::VPC::EIP |
| None |
ALIYUN::NAS::FileSystem |
| None |
ALIYUN::VPC::RouterInterface |
| None |
ALIYUN::ECS::Disk |
| None |
ALIYUN::EHPC::Cluster |
| None |
ALIYUN::ApiGateway::Instance |
| None |
ALIYUN::AMQP::Instance |
| None |
ALIYUN::PrivateLink::VpcEndpointService |
| None |
ALIYUN::GA::Accelerator |
| None |
ALIYUN::CS::ClusterNodePool |
| None |
ALIYUN::CS::ServerlessKubernetesCluster |
| None |
ALIYUN::GWS::Instance |
| None |
ALIYUN::MONGODB::PrepayInstance |
| None |
ALIYUN::Flink::Instance |
| None |
ALIYUN::ECS::InstanceGroupClone |
| None |
ALIYUN::RDS::ReadOnlyDBInstance |
| Note
|
ALIYUN::EMR::Cluster |
| None |
ALIYUN::CloudPhone::InstanceGroup |
| None |
ALIYUN::ECS::PrepayInstance |
| None |
ALIYUN::MONGODB::ShardingInstance |
| None |
ALIYUN::CS::AnyCluster |
| None |
ALIYUN::CDDC::DedicatedHost |
| None |
ALIYUN::ECS::DedicatedHost |
| None |
ALIYUN::SLB::AnyTunnel |
| None |
ALIYUN::VPC::EIPPro |
| None |
ALIYUN::ECD::Desktops |
| None |
ALIYUN::DRDS::DrdsInstance |
| None |
ALIYUN::DTS::SubscriptionInstance |
| None |
ALIYUN::ClickHouse::DBCluster |
| None |
ALIYUN::ECS::PrepayInstanceGroupClone |
| None |
ALIYUN::CEN::CenBandwidthPackage |
| None |
Dependencies between parameters
When you use a template to create Elastic Compute Service (ECS) resources in Resource Orchestration Service (ROS), you must specify parameters such as ZoneInfo
and InstanceType
.
The supported ECS instance types vary based on zones. Therefore, a specific value of the InstanceType
parameter may become unavailable after you specify the ZoneInfo
parameter.
If you want to use only a specific value of the InstanceType
parameter, you can use the Metadata
section to configure the dependencies between parameters.
For more information about the Metadata section, see Metadata.
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
ZoneInfo:
Type: String
InstanceType:
Type: String
Resources:
ECS:
Type: ALIYUN::ECS::Instance
Properties:
ZoneId:
Ref: ZoneInfo
InstanceType:
Ref: InstanceType
ImageId: ubuntu
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- InstanceType
- ZoneInfo
Parameter constraint query for a Terraform template
You can add ResourcesForParameterConstraints to ALIYUN::ROS::Interface in the Metadata section or the .metadata file to configure the constraints of parameters.
You must define the resources relevant to the parameter constraints and specify the resource properties. For more information about the syntax of ResourcesForParameterConstraints, see Resources.
When you query the parameter constraints, the Mappings (optional), Conditions (optional), and Rules (optional) sections defined in the template automatically take effect.
ROSTemplateFormatVersion: '2015-09-01'
Transform: Aliyun::Terraform-v1.1
Workspace:
.metadata: |-
{
"ALIYUN::ROS::Interface": {
"ResourcesForParameterConstraints": {
"instance": {
"Type": "ALIYUN::ECS::Instance",
"Properties": {
"ImageId": {
"Ref": "image_id"
},
"InstanceType": {
"Ref": "instance_type"
},
"ZoneId": {
"Ref": "zone_id"
}
}
}
},
"Hidden": [
"image_id"
]
}
}
main.tf: |-
variable "image_id" {
type = string
default = "ubuntu_18_04_64_20G_alibase_2019****.vhd"
}
variable "instance_type" {
type = string
}
variable "zone_id" {
type = string
}
resource "alicloud_vpc" "vpc" {
cidr_block = "172.16.X.X/16"
}
resource "alicloud_security_group" "group" {
vpc_id = alicloud_vpc.vpc.id
}
resource "alicloud_vswitch" "vswitch" {
vpc_id = alicloud_vpc.vpc.id
cidr_block = "172.16.X.X/24"
zone_id = var.zone_id
}
resource "alicloud_instance" "instance" {
availability_zone = var.zone_id
security_groups = [alicloud_security_group.group.id]
instance_type = var.instance_type
image_id = var.image_id
vswitch_id = alicloud_vswitch.vswitch.id
}
In the preceding Terraform template, four resources are defined. Constraints are configured for the zone_id and instance_type parameters, and the parameters are associated with alicloud_instance.
In ResourcesForParameterConstraints, only the ALIYUN::ECS::Instance resource type of ROS that corresponds to alicloud_instance is defined. The resource type is associated with the image_id, instance_type, and zone_id parameters to configure constraints for these parameters. In this example, the image_id parameter is hidden.