【问题标题】:Terraform - Elastic Beanstalk - How to Swap Environment URLsTerraform - Elastic Beanstalk - 如何交换环境 URL
【发布时间】:2018-11-01 20:04:47
【问题描述】:
我正在尝试使用 terraform/elastic beanstalk 完成蓝/绿部署。一个如何用这个堆栈交换环境 URL?我在这里看不到任何明显的东西。
我能想到的最好的是......
- 运行一个 terraform apply 来启动我的整个架构
- 旋转
aws_elastic_beanstalk_environment 的蓝色环境
- 当想要部署新版本的应用程序时,运行
terraform
apply module.elasticbeanstalk.aws_elastic_beanstalk_environment.green 以仅启动其他 aws_elastic_beanstalk_environment 资源
- 现在我有蓝色和绿色了。实际交换 URL 的时间...
- 通过命令行
eb swap API,交换两个环境URL
- 手动更新 tfstate
-
terraform push新状态
如果有一个我不必手动操作状态的解决方案,我会很高兴的。或者这是使用这两个工具完成此功能的唯一方法?
【问题讨论】:
标签:
amazon-elastic-beanstalk
terraform
terraform-provider-aws
【解决方案2】:
如果您希望在交换后更新状态,您可以记下 beanstalk 环境的 id 并执行以下操作:
# Remove the old state information, using the command line not manually
terraform state rm module.elasticbeanstalk.aws_elastic_beanstalk_environment.blue
terraform state rm module.elasticbeanstalk.aws_elastic_beanstalk_environment.green
# Import these to the opposite environment resources
terraform import module.elasticbeanstalk.aws_elastic_beanstalk_environment.blue <green id>
terraform import module.elasticbeanstalk.aws_elastic_beanstalk_environment.green <blue id>
这似乎不太理想,但它确实避免了需要手动操作状态文件并且可以轻松编写脚本。