2017-02-03 6 views
0

我正在使用Terraform部署數據庫服務器與初始數據庫和用戶。如何將延遲添加到postgresql_database創建後aws_db_instance

Terraform文件安裝得很好AFAICS,但postgresql_role和postgresql_database操作失敗,因爲數據庫(Amazon RDS)在調用時仍在安裝。

是否有Terraform方式添加強制等待?或者顯式檢查數據庫是否可用?

回答

1

可以使用local-exec provisioner實現等待很輕鬆地:

variable "database_delay" { default = 60 } 

resource "aws_db_instance" "default" { 
    allocated_storage = 10 
    engine    = "postgres" 
    engine_version  = "9.6.1" 
    instance_class  = "db.t2.micro" 
    name     = "mydb" 
    username    = "foo" 
    password    = "bar" 
    db_subnet_group_name = "my_database_subnet_group" 
    parameter_group_name = "postgres9.6" 

    provisioner "local-exec" { 
    command = "sleep ${var.database_delay}" 
    } 
} 

在我設置上移動到任何其他依賴之前創建數據庫實例時,它只需等待60秒以上的例子資源/模塊(如progresql_database資源)。顯然,您仍然需要確保Terraform可以遵循的依賴鏈知道它必須首先完成aws_db_instance的創建。