首页 文章

Terraform - Elastic Beanstalk - 如何交换环境URL

提问于
浏览
0

我正在尝试使用terraform / elastic beanstalk完成蓝/绿部署 . 如何使用此堆栈交换环境URL?我在这里看不到任何明显的东西 .

我能想到的最好的是......

  • 运行terraform适用于旋转我的整个架构

  • 旋转了 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 新州

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

1 回答

  • 0

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

    这看起来并不完美,但它确实避免了需要手动操作状态文件,并且可以很容易地编写脚本 .

相关问题