【问题标题】:How to swap between two resources in terraform如何在terraform中的两个资源之间交换
【发布时间】:2022-08-22 22:30:14
【问题描述】:

我错误地将resource1的id导入resource2的地址,反之亦然。 我如何在它们之间进行交换?

例如:我有两个 aws 实例,但第一个实例的 id 被导入到第二个实例的资源地址,第二个实例的 id 被导入到第一个实例。

    标签: terraform


    【解决方案1】:

    我创建了以下 bash 脚本来在资源之间进行交换:

    export SECOND_RESOURCE_ID="i-222"
    
    export FIRST_RESOURCE="aws_instance.first-instance"
    export SECOND_RESOURCE="aws_instance.second-instance"
    
    terraform state rm ${FIRST_RESOURCE} 
    terraform state mv ${SECOND_RESOURCE} ${FIRST_RESOURCE} 
    terraform import ${SECOND_RESOURCE} ${SECOND_RESOURCE_ID}
    

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 2021-06-14
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 2022-07-28
      • 1970-01-01
      相关资源
      最近更新 更多