2

我正在尝试使用 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 swapAPI,交换两个环境 URL
    • 手动更新 tfstate
    • terraform push新状态

如果有一个我不必手动操作状态的解决方案,我会喜欢的。或者这是使用这两个工具完成此功能的唯一方法?

4

2 回答 2

0

我相信您只需切换每个的cname 前缀

于 2019-08-21T20:23:40.150 回答
-1

如果您希望在交换后更新状态,您可以记下 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>

这看起来并不完全理想,但它确实避免了需要手动操作状态文件并且可以轻松地编写童话脚本。

于 2018-05-28T02:34:22.160 回答