Skip to content

Commit

Permalink
Merge pull request hashicorp#23 from hashicorp/master
Browse files Browse the repository at this point in the history
sync upstream
  • Loading branch information
pmoust committed Apr 5, 2015
2 parents 2208979 + 2b294dd commit a0e3d33
Show file tree
Hide file tree
Showing 85 changed files with 3,591 additions and 433 deletions.
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.4.0 (unreleased)
## 0.4.1 (unreleased)



## 0.4.0 (April 2, 2015)

BACKWARDS INCOMPATIBILITIES:

Expand All @@ -8,6 +12,11 @@ BACKWARDS INCOMPATIBILITIES:
consolidates all remote state management under one command.
* Period-prefixed configuration files are now ignored. This might break
existing Terraform configurations if you had period-prefixed files.
* The `block_device` attribute of `aws_instance` has been removed in favor
of three more specific attributes to specify block device mappings:
`root_block_device`, `ebs_block_device`, and `ephemeral_block_device`.
Configurations using the old attribute will generate a validation error
indicating that they must be updated to use the new fields [GH-1045].

FEATURES:

Expand All @@ -16,6 +25,9 @@ FEATURES:
using the standard Docker API. [GH-855]
* **New provider: `openstack` (OpenStack)** - Interact with the many resources
provided by OpenStack. [GH-924]
* **New feature: `terraform_remote_state` resource** - Reference remote
states from other Terraform runs to use Terraform outputs as inputs
into another Terraform run.
* **New command: `taint`** - Manually mark a resource as tainted, causing
a destroy and recreate on the next plan/apply.
* **New resource: `aws_vpn_gateway`** [GH-1137]
Expand Down Expand Up @@ -56,7 +68,13 @@ IMPROVEMENTS:
* providers/aws: Add a short syntax for Route 53 Record names, e.g.
`www` instead of `www.example.com`.
* providers/aws: Improve dependency violation error handling, when deleting
Internet Gateways or Auto Scaling groups [GH-1325].
Internet Gateways or Auto Scaling groups [GH-1325].
* provider/aws: Add non-destructive updates to AWS RDS. You can now upgrade
`egine_version`, `parameter_group_name`, and `multi_az` without forcing
a new database to be created.[GH-1341]
* providers/aws: Full support for block device mappings on instances and
launch configurations [GH-1045, GH-1364]
* provisioners/remote-exec: SSH agent support. [GH-1208]

BUG FIXES:

Expand Down
12 changes: 12 additions & 0 deletions builtin/bins/provider-terraform/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"github.com/hashicorp/terraform/builtin/providers/terraform"
"github.com/hashicorp/terraform/plugin"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: terraform.Provider,
})
}
1 change: 1 addition & 0 deletions builtin/bins/provider-terraform/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
4 changes: 4 additions & 0 deletions builtin/providers/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
"github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/hashicorp/aws-sdk-go/gen/iam"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/aws-sdk-go/gen/route53"
"github.com/hashicorp/aws-sdk-go/gen/s3"
Expand All @@ -30,6 +31,7 @@ type AWSClient struct {
r53conn *route53.Route53
region string
rdsconn *rds.RDS
iamconn *iam.IAM
}

// Client configures and returns a fully initailized AWSClient
Expand Down Expand Up @@ -70,6 +72,8 @@ func (c *Config) Client() (interface{}, error) {
client.r53conn = route53.New(creds, "us-east-1", nil)
log.Println("[INFO] Initializing EC2 Connection")
client.ec2conn = ec2.New(creds, c.Region, nil)

client.iamconn = iam.New(creds, c.Region, nil)
}

if len(errs) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckAWSAutoScalingGroupAttributes(&group),
resource.TestCheckResourceAttr(
"aws_autoscaling_group.bar", "availability_zones.1807834199", "us-west-2a"),
"aws_autoscaling_group.bar", "availability_zones.2487133097", "us-west-2a"),
resource.TestCheckResourceAttr(
"aws_autoscaling_group.bar", "name", "foobar3-terraform-test"),
resource.TestCheckResourceAttr(
Expand Down
156 changes: 130 additions & 26 deletions builtin/providers/aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/iam"
"github.com/hashicorp/aws-sdk-go/gen/rds"

"github.com/hashicorp/terraform/helper/hashcode"
Expand All @@ -17,6 +18,7 @@ func resourceAwsDbInstance() *schema.Resource {
return &schema.Resource{
Create: resourceAwsDbInstanceCreate,
Read: resourceAwsDbInstanceRead,
Update: resourceAwsDbInstanceUpdate,
Delete: resourceAwsDbInstanceDelete,

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -47,7 +49,6 @@ func resourceAwsDbInstance() *schema.Resource {
"engine_version": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"storage_encrypted": &schema.Schema{
Expand Down Expand Up @@ -119,7 +120,6 @@ func resourceAwsDbInstance() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},

"port": &schema.Schema{
Expand All @@ -138,6 +138,7 @@ func resourceAwsDbInstance() *schema.Resource {
"vpc_security_group_ids": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int {
return hashcode.String(v.(string))
Expand All @@ -162,13 +163,13 @@ func resourceAwsDbInstance() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"parameter_group_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"address": &schema.Schema{
Expand All @@ -185,12 +186,24 @@ func resourceAwsDbInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

// apply_immediately is used to determine when the update modifications
// take place.
// See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html
"apply_immediately": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"tags": tagsSchema(),
},
}
}

func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{}))
opts := rds.CreateDBInstanceMessage{
AllocatedStorage: aws.Integer(d.Get("allocated_storage").(int)),
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
Expand All @@ -201,6 +214,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
Engine: aws.String(d.Get("engine").(string)),
EngineVersion: aws.String(d.Get("engine_version").(string)),
StorageEncrypted: aws.Boolean(d.Get("storage_encrypted").(bool)),
Tags: tags,
}

if attr, ok := d.GetOk("storage_type"); ok {
Expand Down Expand Up @@ -304,33 +318,60 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

if v.DBName != nil {
d.Set("name", *v.DBName)
} else {
d.Set("name", "")
}
d.Set("username", *v.MasterUsername)
d.Set("engine", *v.Engine)
d.Set("engine_version", *v.EngineVersion)
d.Set("allocated_storage", *v.AllocatedStorage)
d.Set("storage_type", *v.StorageType)
d.Set("instance_class", *v.DBInstanceClass)
d.Set("availability_zone", *v.AvailabilityZone)
d.Set("backup_retention_period", *v.BackupRetentionPeriod)
d.Set("backup_window", *v.PreferredBackupWindow)
d.Set("maintenance_window", *v.PreferredMaintenanceWindow)
d.Set("multi_az", *v.MultiAZ)
d.Set("port", *v.Endpoint.Port)
d.Set("db_subnet_group_name", *v.DBSubnetGroup.DBSubnetGroupName)
d.Set("name", v.DBName)
d.Set("username", v.MasterUsername)
d.Set("engine", v.Engine)
d.Set("engine_version", v.EngineVersion)
d.Set("allocated_storage", v.AllocatedStorage)
d.Set("storage_type", v.StorageType)
d.Set("instance_class", v.DBInstanceClass)
d.Set("availability_zone", v.AvailabilityZone)
d.Set("backup_retention_period", v.BackupRetentionPeriod)
d.Set("backup_window", v.PreferredBackupWindow)
d.Set("maintenance_window", v.PreferredMaintenanceWindow)
d.Set("multi_az", v.MultiAZ)
if v.DBSubnetGroup != nil {
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
}

if len(v.DBParameterGroups) > 0 {
d.Set("parameter_group_name", *v.DBParameterGroups[0].DBParameterGroupName)
d.Set("parameter_group_name", v.DBParameterGroups[0].DBParameterGroupName)
}

d.Set("address", *v.Endpoint.Address)
d.Set("endpoint", fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port))
d.Set("status", *v.DBInstanceStatus)
d.Set("storage_encrypted", *v.StorageEncrypted)
if v.Endpoint != nil {
d.Set("port", v.Endpoint.Port)
d.Set("address", v.Endpoint.Address)

if v.Endpoint.Address != nil && v.Endpoint.Port != nil {
d.Set("endpoint",
fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port))
}
}

d.Set("status", v.DBInstanceStatus)
d.Set("storage_encrypted", v.StorageEncrypted)

// list tags for resource
// set tags
conn := meta.(*AWSClient).rdsconn
arn, err := buildRDSARN(d, meta)
if err != nil {
log.Printf("[DEBUG] Error building ARN for DB Instance, not setting Tags for DB %s", *v.DBName)
} else {
resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceMessage{
ResourceName: aws.String(arn),
})

if err != nil {
log.Printf("[DEBUG] Error retreiving tags for ARN: %s", arn)
}

var dt []rds.Tag
if len(resp.TagList) > 0 {
dt = resp.TagList
}
d.Set("tags", tagsToMapRDS(dt))
}

// Create an empty schema.Set to hold all vpc security group ids
ids := &schema.Set{
Expand Down Expand Up @@ -394,6 +435,56 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error
return nil
}

func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn

d.Partial(true)
// Change is used to determine if a ModifyDBInstanceMessage request actually
// gets sent.
change := false

req := &rds.ModifyDBInstanceMessage{
ApplyImmediately: aws.Boolean(d.Get("apply_immediately").(bool)),
DBInstanceIdentifier: aws.String(d.Id()),
}

if d.HasChange("engine_version") {
change = true
d.SetPartial("engine_version")
req.EngineVersion = aws.String(d.Get("engine_version").(string))
}

if d.HasChange("multi_az") {
change = true
d.SetPartial("multi_az")
req.MultiAZ = aws.Boolean(d.Get("multi_az").(bool))
}

if d.HasChange("parameter_group_name") {
change = true
d.SetPartial("parameter_group_name")
req.DBParameterGroupName = aws.String(d.Get("parameter_group_name").(string))
}

if change {
log.Printf("[DEBUG] DB Instance Modification request: %#v", req)
_, err := conn.ModifyDBInstance(req)
if err != nil {
return fmt.Errorf("Error mofigying DB Instance %s: %s", d.Id(), err)
}
}

if arn, err := buildRDSARN(d, meta); err == nil {
if err := setTagsRDS(conn, d, arn); err != nil {
return err
} else {
d.SetPartial("tags")
}
}
d.Partial(false)
return resourceAwsDbInstanceRead(d, meta)
}

func resourceAwsBbInstanceRetrieve(
d *schema.ResourceData, meta interface{}) (*rds.DBInstance, error) {
conn := meta.(*AWSClient).rdsconn
Expand Down Expand Up @@ -443,3 +534,16 @@ func resourceAwsDbInstanceStateRefreshFunc(
return v, *v.DBInstanceStatus, nil
}
}

func buildRDSARN(d *schema.ResourceData, meta interface{}) (string, error) {
iamconn := meta.(*AWSClient).iamconn
region := meta.(*AWSClient).region
// An zero value GetUserRequest{} defers to the currently logged in user
resp, err := iamconn.GetUser(&iam.GetUserRequest{})
if err != nil {
return "", err
}
user := resp.User
arn := fmt.Sprintf("arn:aws:rds:%s:%s:db:%s", region, *user.UserID, d.Id())
return arn, nil
}
14 changes: 8 additions & 6 deletions builtin/providers/aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package aws

import (
"fmt"
"math/rand"
"testing"
"time"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand All @@ -24,8 +26,6 @@ func TestAccAWSDBInstance(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
testAccCheckAWSDBInstanceAttributes(&v),
resource.TestCheckResourceAttr(
"aws_db_instance.bar", "identifier", "foobarbaz-test-terraform"),
resource.TestCheckResourceAttr(
"aws_db_instance.bar", "allocated_storage", "10"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -133,9 +133,12 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
}
}

const testAccAWSDBInstanceConfig = `
// Database names cannot collide, and deletion takes so long, that making the
// name a bit random helps so able we can kill a test that's just waiting for a
// delete and not be blocked on kicking off another one.
var testAccAWSDBInstanceConfig = fmt.Sprintf(`
resource "aws_db_instance" "bar" {
identifier = "foobarbaz-test-terraform"
identifier = "foobarbaz-test-terraform-%d"
allocated_storage = 10
engine = "mysql"
Expand All @@ -148,5 +151,4 @@ resource "aws_db_instance" "bar" {
backup_retention_period = 0
parameter_group_name = "default.mysql5.6"
}
`
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
Loading

0 comments on commit a0e3d33

Please sign in to comment.