[英]How do I connect rds with elastic beanstalk in terraform
I have the code to create the elastic beanstalk with terraform and here is the code I found in terraform docs to create an rds instance我有使用 terraform 创建弹性 beantalk 的代码,这是我在 terraform 文档中找到的用于创建 rds 实例的代码
resource "aws_db_instance" "default" {
allocated_storage = 10
db_name = "mydb"
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t3.micro"
username = "foo"
password = "foobarbaz"
parameter_group_name = "default.mysql5.7"
skip_final_snapshot = true
}
The problem is that I can't find an example of how to connect this db to elastic beanstalk问题是我找不到如何将此数据库连接到弹性 beanstalk 的示例
I think the setting
option should be the way to go here, ie, you probably do not need a separate resource for creating the DB.我认为
setting
选项应该是 go 的方式,即,您可能不需要单独的资源来创建数据库。 Based on the AWS docs [1], and using the terraform examples [2], it should be something like:基于 AWS 文档 [1],并使用 terraform 示例 [2],它应该类似于:
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name"
application = aws_elastic_beanstalk_application.tftest.name
solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4"
setting {
namespace = "aws:rds:dbinstance"
name = "DBAllocatedStorage"
value = "10"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBDeletionPolicy"
value = "Delete"
}
setting {
namespace = "aws:rds:dbinstance"
name = "HasCoupledDatabase"
value = "true"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBEngine"
value = "mysql"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBEngineVersion"
value = "5.7"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBInstanceClass"
value = "db.t3.micro"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBPassword"
value = "foobarbaz"
}
setting {
namespace = "aws:rds:dbinstance"
name = "DBUser"
value = "foo"
}
}
However, I am not sure if the parameter_group_name
can be set here.但是,我不确定这里是否可以设置
parameter_group_name
。
EDIT: Answer updated to create a DB instance with the ElasticBeanstalk environment.编辑:更新答案以使用 ElasticBeanstalk 环境创建数据库实例。 However, make sure to understand this part about
HasCoupledDatabase
setting from the docs:但是,请确保从文档中了解有关
HasCoupledDatabase
设置的这一部分:
Note: If you toggle this value back to
true
after decoupling the previous database, Elastic Beanstalk creates a new database with the previous database option settings.注意:如果在分离之前的数据库后将此值切换回
true
,Elastic Beanstalk 会使用之前的数据库选项设置创建一个新数据库。 However, to maintain the security of your environment, it doesn't retain the existing DBUser and DBPassword settings.但是,为了维护环境的安全,它不会保留现有的 DBUser 和 DBPassword 设置。 You need to specify DBUser and DBPassword again .
您需要再次指定 DBUser 和 DBPassword 。
[1] https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-rdsdbinstance [1] https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-rdsdbinstance
[2] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elastic_beanstalk_environment#option-settings [2] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elastic_beanstalk_environment#option-settings
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.