如何解决使用Terraform基于参数化名称创建多个aws_cloudformation_stack
是否可以基于参数化名称在terraform中使用一个 Process: com.gamze.pawsbook,PID: 30879
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.<init>(JSONObject.java:159)
at org.json.JSONObject.<init>(JSONObject.java:176)
at com.gamze.pawsbook.MapActivitiy$ParserTask.doInBackground(MapActivitiy.java:225)
at com.gamze.pawsbook.MapActivitiy$ParserTask.doInBackground(MapActivitiy.java:215)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
资源定义创建多个CloutFormation堆栈?
我定义了以下资源,并且希望每个aws_cloudformation_stack
,app_name
app_env
组合都有一个堆栈:
build_name
当resource "aws_s3_bucket_object" "sam_deploy_object" {
bucket = var.sam_bucket
key = "${var.app_env}/${var.build_name}/sam_template_${timestamp()}.yaml"
source = "../.aws-sam/sam_template_output.yaml"
etag = filemd5("../.aws-sam/sam_template_output.yaml")
}
resource "aws_cloudformation_stack" "subscriptions_sam_stack" {
name = "${var.app_name}---${var.app_env}--${var.build_name}"
capabilities = ["CAPABILITY_NAMED_IAM","CAPABILITY_AUTO_EXPAND"]
template_url = "https://${var.sam_bucket}.s3-${data.aws_region.current.name}.amazonaws.com/${aws_s3_bucket_object.sam_deploy_object.id}"
}
名称更改时运行terraform apply
时,旧堆栈将被删除并创建一个新堆栈,但是我想保留旧堆栈并创建一个新堆栈
解决方法
一种方法是将变量//add bar
$("#btn-Newbar").on("click",function() {
$("#hbar").append("<div class='col-4' style='margin-bottom:20px;'><div class='row'><div class='col-3'><img src='' class='catHpic' style='height:80px;width:80px;'></div><div class='col-9'><input type='file' class='hpicFile'><div class='input-group mb-3' style='margin-top:10px;'><div class='input-group-prepend'><span class='input-group-text url'>URL</span></div><input type='text' class='form-control' aria-describedby='basic-addon1'></div></div></div></div>");
});
//display highlight pic real time
$(document).on("change",".hpicFile",function(e) {
var imgSrc = $(this).parent('div').prev().find('.catHpic') //find img
if (e.target.files[0] != null) {
//console.log(e.target.files[0]);
$.each(this.files,function(key,file) {
var reader = new FileReader();
reader.onload = function(e) {
//display images real time
imgSrc.attr('src',e.target.result);
}
reader.readAsDataURL(file);
});
}
});
定义为列表。然后,当您创建新的内部版本时,只需将它们附加到列表中,并借助for_each创建堆栈以遍历内部版本名称。
例如,如果您具有以下条件:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card-body">
<div class="row" id="hbar">
</div>
</div>
<div class="card-footer" style="text-align:right;">
<button class="btn btn-secondary" id="btn-Newbar">New Bar</button>
</div>
然后,如果要为堆栈进行第二次构建,则只需扩展build_name
:
variable "app_name" {
default = "test1"
}
variable "app_env" {
default = "test2"
}
variable "build_name" {
default = ["test3"]
}
resource "aws_cloudformation_stack" "subscriptions_sam_stack" {
for_each = toset(var.build_name)
name = "${var.app_name}---${var.app_env}--${each.value}"
capabilities = ["CAPABILITY_NAMED_IAM","CAPABILITY_AUTO_EXPAND"]
template_url = "https://${var.sam_bucket}.s3-${data.aws_region.current.name}.amazonaws.com/${aws_s3_bucket_object.sam_deploy_object.id}"
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。