From 45ef11e59f443c43b42fe2d36c639c55bb0b1fbd Mon Sep 17 00:00:00 2001 From: Koen De Causmaecker Date: Wed, 9 Sep 2015 14:06:53 +0200 Subject: [PATCH] provider/aws: aws_db_instance: unrequire fields When spinning up from a snapshot or a read replica, these fields are now optional: * allocated_storage * engine * password * username Some validation logic is added to make these fields required when starting a database from scratch. The documentation is updated accordingly. --- .../providers/aws/resource_aws_db_instance.go | 23 +++++++++++++++---- .../providers/aws/r/db_instance.html.markdown | 8 +++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 00de73fc7..9bc6669a5 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -38,18 +38,20 @@ func resourceAwsDbInstance() *schema.Resource { "username": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, ForceNew: true, }, "password": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, }, "engine": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, ForceNew: true, StateFunc: func(v interface{}) string { value := v.(string) @@ -71,7 +73,8 @@ func resourceAwsDbInstance() *schema.Resource { "allocated_storage": &schema.Schema{ Type: schema.TypeInt, - Required: true, + Optional: true, + Computed: true, }, "storage_type": &schema.Schema{ @@ -405,6 +408,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } } else { + if _, ok := d.GetOk("allocated_storage"); !ok { + return fmt.Errorf(`provider.aws: aws_db_instance: %s: "allocated_storage": required field is not set`, d.Get("name").(string)) + } + if _, ok := d.GetOk("engine"); !ok { + return fmt.Errorf(`provider.aws: aws_db_instance: %s: "engine": required field is not set`, d.Get("name").(string)) + } + if _, ok := d.GetOk("password"); !ok { + return fmt.Errorf(`provider.aws: aws_db_instance: %s: "password": required field is not set`, d.Get("name").(string)) + } + if _, ok := d.GetOk("username"); !ok { + return fmt.Errorf(`provider.aws: aws_db_instance: %s: "username": required field is not set`, d.Get("name").(string)) + } opts := rds.CreateDBInstanceInput{ AllocatedStorage: aws.Int64(int64(d.Get("allocated_storage").(int))), DBName: aws.String(d.Get("name").(string)), diff --git a/website/source/docs/providers/aws/r/db_instance.html.markdown b/website/source/docs/providers/aws/r/db_instance.html.markdown index 2c045773c..f3e4eb708 100644 --- a/website/source/docs/providers/aws/r/db_instance.html.markdown +++ b/website/source/docs/providers/aws/r/db_instance.html.markdown @@ -48,8 +48,8 @@ the [AWS official documentation](http://docs.aws.amazon.com/AmazonRDS/latest/Com The following arguments are supported: -* `allocated_storage` - (Required) The allocated storage in gigabytes. -* `engine` - (Required) The database engine to use. +* `allocated_storage` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The allocated storage in gigabytes. +* `engine` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The database engine to use. * `engine_version` - (Optional) The engine version to use. * `identifier` - (Required) The name of the RDS instance * `instance_class` - (Required) The instance type of the RDS instance. @@ -65,9 +65,9 @@ the final snapshot (if `final_snapshot_identifier` is specified). Default `false` * `name` - (Optional) The DB name to create. If omitted, no database is created initially. -* `password` - (Required) Password for the master DB user. Note that this may +* `password` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. -* `username` - (Required) Username for the master DB user. +* `username` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Username for the master DB user. * `availability_zone` - (Optional) The AZ for the RDS instance. * `backup_retention_period` - (Optional) The days to retain backups for. Must be `1` or greater to be a source for a [Read Replica][1].