简体   繁体   English

如何在 terraform 中将 rds 与弹性 beantalk 连接

[英]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.

相关问题 当我将 SpringBoot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 SpringBoot 连接到 RDS 时出现 502 bad gateway - 502 bad gateway when I deploy SpringBoot application to AWS Elastic Beanstalk and cannot connect to RDS from local SpringBoot 如何在 AWS Elastic Beanstalk 上设置和使用 Laravel 调度? - How do I setup and use Laravel Scheduling on AWS Elastic Beanstalk? 无法在我的笔记本电脑上连接到 AWS RDS(尽管我的 laravel 应用程序通过弹性 beantalk 托管可以与 RDS 交互) - Unable to connect to AWS RDS on my laptop (although my laravel app which is hosted via elastic beanstalk can interact with the RDS) 我无法将 Elasticache 连接到 Elastic Beanstalk(在 VPC 中) - I can't connect Elasticache to Elastic Beanstalk (In VPC) Elastic Beanstalk HTTP 至 HTTPS 重定向至 Terraform - Elastic Beanstalk HTTP to HTTPS Redirect In Terraform 使用 terraform 从弹性 beantalk 应用程序设置弹性负载平衡的密码 - Setting the cipher for an elastic load balance from an elastic beanstalk app with terraform 如何解决 Elastic Beanstalk 部署期间的“OSError: mysql_config not found”错误? - How do I address "OSError: mysql_config not found" error during Elastic Beanstalk deployment? 如何设置Terraform中elasticsearch索引的总字段数限制? - How do I set the total field limit of an elastic search index in Terraform? 在 Django/Elastic beanstalk/RDS 上更改 MySQL 隔离级别 - Changing MySQL isolation level on Django/Elastic beanstalk/RDS 如何将 RDS 实例附加到 Terraform 中的安全组 - How can I attach a RDS Instance to a Security Group in Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM