本文介绍了Terraform 中的 Elastic Beanstalk 应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过参数化名称来管理我的 terraform 模板中的应用程序版本.这是一种尝试,只要应用程序的内容发生变化,我们的 CI 流程就会创建一个新的应用程序版本.这样,在 elasticbeanstalk 中,我可以保留历史应用程序版本的列表,以便我可以回滚等.这不起作用,因为同一应用程序版本不断更新,实际上我丢失了所有应用程序版本的历史记录.

I attempted to manage my application versions in my terraform template by parameterising the name. This was an attempt to have a new application version created by our CI process whenever the contents of the application changed. This way in elasticbeanstalk i could keep a list of historic application versions so that i could roll back etc. This didnt work as the same application version was constantly updated and in effect i lost the history of all application versions.

resource "aws_elastic_beanstalk_application_version" "default" {
   name        = "${var.eb-app-name}-${var.build-number}"
   application = "${var.eb-app-name}"
   description = "application version created by terraform"
   bucket      = "${aws_s3_bucket.default.id}"
   key         = "${aws_s3_bucket_object.default.id}"
}

然后我尝试参数化逻辑资源引用名称,但 terraform 不支持.

I then tried to parameterise the logical resource reference name, but this isnt supported by terraform.

resource "aws_elastic_beanstalk_application_version" "${var.build-number}" {
   name        = "${var.eb-app-name}-${var.build-number}"
   application = "${var.eb-app-name}"
   description = "application version created by terraform"
   bucket      = "${aws_s3_bucket.default.id}"
   key         = "${aws_s3_bucket_object.default.id}"
}

目前我的解决方案是在 terraform 之外管理我的应用程序版本,这令人失望,因为还有其他相关资源,例如 S3 存储桶和权限需要担心.

Currently my solution is to manage my application versions outside of terraform which is disappointing as there are other associated resources such as the S3 bucket and permissions to worry about.

我错过了什么吗?

推荐答案

就 Terraform 而言,您只是在那里更新单个 EB 应用程序版本资源.如果您想保留以前的版本,那么您可能需要尝试增加 Terraform 管理的资源数量.

As far as Terraform is concerned you are just updating a single EB application version resource there. If you wanted to keep the previous versions around then you might need to try and increment the count of resources that Terraform is managing.

在我的脑海中,你可以尝试这样的事情:

Off the top of my head you could try something like this:

variable "builds" = {
  type = list
}

resource "aws_elastic_beanstalk_application_version" "default" {
   count       = "${length(var.builds)}"
   name        = "${var.eb-app-name}-${element(builds, count.index)}"
   application = "${var.eb-app-name}"
   description = "application version created by terraform"
   bucket      = "${aws_s3_bucket.default.id}"
   key         = "${aws_s3_bucket_object.default.id}"
}

然后,如果您有一个 builds 列表,它应该为每个 build 创建一个新的应用程序版本.

Then if you have a list of builds it should create a new application version for each build.

当然,这可能是动态的,因为变量可以是返回所有构建列表的数据源.如果数据源不存在,您可以编写一个小脚本用作 外部数据源.

Of course that could be dynamic in that the variable could instead be a data source that returns a list of all your builds. If a data source doesn't exist for it already you could write a small script that is used as an external data source.

这篇关于Terraform 中的 Elastic Beanstalk 应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:55