首页 > 解决方案 > AWS 会话令牌在运行 terraform apply 时过期

问题描述

在 terraform 中使用 AWS 会话令牌。RDS 恢复需要一个多小时,同时会话令牌会过期。因此,tf 状态文件也没有在 s3 中更新。有没有办法在后台运行 tf apply 以便我们可以定期刷新令牌并且操作不会失败?

11:07:25    status code: 400, request id: PF3V9137RT1HVB3W, host id: SeXwAFlokygO5NjyKppBD/kYvFl/i9nrh81YSf7Szta6y5Wfd20ssxmFYYwhg+XysuPMvb1uuJo=
11:07:25  
11:07:25  
11:07:25  Error: Failed to persist state to backend.
11:07:25  
11:07:25  The error shown above has prevented Terraform from writing the updated state
11:07:25  to the configured backend. To allow for recovery, the state has been written
11:07:25  to the file "errored.tfstate" in the current working directory.
11:07:25  
11:07:25  Running "terraform apply" again at this point will create a forked state,
11:07:25  making it harder to recover.
11:07:25  
11:07:25  To retry writing this state, use the following command:
11:07:25      terraform state push errored.tfstate
11:07:25  
11:07:25  
11:07:25  
11:07:25  Releasing state lock. This may take a few moments...
11:07:30  
11:07:30  Error releasing the state lock!
11:07:30  
11:07:30  Error message: failed to retrieve lock info: ExpiredTokenException: The security token included in the request is expired
11:07:30    status code: 400, request id: C7JE11FDGLPTU672G4781LOR73VV4KQNSO5AEMVJF66Q9ASUAAJG

标签: amazon-web-servicessessionterraformtokenamazon-rds

解决方案


通过将过程分为两个步骤来获得解决方法。当我创建一个多可用区 RDS 实例时,创建过程花费了大量时间。作为解决方案:

  • 首先我们可以使用 terraform 创建一个单可用区实例。
  • 然后再次使用它来修改实例成为多可用区。

这对我有用。


推荐阅读