请找到Variable.tf文件的样本代码段,我只想获取subscription_id,plan_id,user_id。我不想获取位置,因为它已经设置了默认值。
variable "subscription_id" {
description = "My subscription id"
}
variable "plan_id" {
description = "My tenant id"
}
variable "user_id" {
description = "My user id"
}
variable "location" {
type="string"
default="Sydney"
description="The name of the location in which your account is
created. "
}
答案 0 :(得分:0)
您可以使用正则表达式查找各种变量,然后使用另一个正则表达式解析找到的变量。一种做到这一点的方法是以下
Map<String, Map<String,String>> parse(String input){
HashMap<String, Map<String, String>> variables = new HashMap<>();
Matcher variableMatcher = Pattern.compile("variable \"(\\S+?)\"\\s*\\{\\s*((?:.|\\n)+?)\\s*}").matcher(input);
Pattern bodyElementPattern = Pattern.compile("(\\S+)\\s*=\\s*\"(.+)\"");
while (variableMatcher.find()){
HashMap<String, String> bodyElements = new HashMap<>();
Matcher bodyElementMatcher = bodyElementPattern.matcher(variableMatcher.group(2));
while (bodyElementMatcher.find()){
bodyElements.put(bodyElementMatcher.group(1),bodyElementMatcher.group(2));
}
variables.put(variableMatcher.group(1),bodyElements);
}
return variables;
}
在这里,您将获得一个变量名到变量内容的映射,其中变量Contents被表示为组件名称和值的另一个映射。