如何解决dashboard_body内的模板文件
我想知道是否有可能在dashboard_body资源中使用模板文件。我正在尝试以下方法。
dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric","x": 0,"y": 0,"width": 12,"height": 6,"properties": {
"metrics": [
templatefile("${path.module}/backends.tmpl",{ instances = aws_instance.web })
],"period": 300,"stat": "Average","region": "us-east-1","title": "EC2 Instance CPU"
}
}
]
}
EOF
使用模板文件
%{ for instance in instances ~}
[
"AWS/EC2","CPUUtilization","InstanceId","${instance.id}"
]
%{ endfor ~}
但是,当我运行Terraform Apply时,出现以下错误消息。
错误:“ dashboard_body”包含无效的JSON:字面值为true的无效字符“ e”(预期为“ r”)
在dashboards.tf第1行中,在资源“ aws_cloudwatch_dashboard”“ main”中: 1:资源“ aws_cloudwatch_dashboard”“主要” {
预先感谢您的帮助。
解决方法
是的,您可以使用模板文件。看来您在这里有一个小的语法错误:
app = Flask(__name__)
CORS(app)
app.config.from_object('app_config')
app.secret_key = ''
client = Client(sid,token)
limiter = Limiter(
app,key_func=get_remote_address,default_limits=["5 per day","1 per second"],)
@app.route("/start",methods=["POST"])
@limiter.limit("3 per day")
@requires_auth
def start():
agent = request.headers['Agent']
uagent = request.headers.get('Ugent')
path = request.path
if agent_check(agent) == False:
ip = request.remote_addr
return jsonify(success=False,message="Hey!Why are you here.")
country_code = request.values.get("c")
phone_number = request.values.get("n")
chan = request.values.get("v")
full_phone = "+{}{}".format(country_code,phone_number)
SERVICE = app.config['VERIFY_SERVICE_SID']
keep_log()
try:
r = client.verify \
.services(SERVICE) \
.verifications \
.create(to=full_phone,channel=chan)
return jsonify(success=True,message="Verification sent to {}".format(r.to))
except Exception as e:
return jsonify(success=False,message="Error sending verification: {}".format(e))
@app.route("/check",methods=["POST"])
@limiter.limit("3 per day")
@requires_auth
def check():
agent=request.headers['Agent']
uagent = request.headers.get('UAgent')
path = request.path
ip = request.remote_addr
if agent_check(agent)==False:
return jsonify(success=False,message="Hey!Why are you here.")
if not request.values.get("c") or not request.values.get("v") or not request.values.get("n"):
return jsonify(success=False,message="Wrong parameters")
country_code = request.values.get("c")
phone_number = request.values.get("n")
full_phone = "+{}{}".format(country_code,phone_number)
code = request.values.get("vc")
SERVICE = app.config['VERIFY_SERVICE_SID']
keep_log()
try:
r = client.verify \
.services(SERVICE) \
.verification_checks \
.create(to=full_phone,code=code)
if r.status == "approved":
return jsonify(success=True,message="Valid token.")
else:
return jsonify(success=False,message="Invalid token.")
except Exception as e:
return jsonify(success=False,message="Error checking verification: {}".format(e))
您应将整个函数包装在插值块中,如下所示:
templatefile("${path.module}/backends.tmpl",{ instances = aws_instance.web })
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。