Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into updatefresh
Browse files Browse the repository at this point in the history
* origin/master:
  update CHANGELOG
  provider/aws: fix vet error, missing fmt param
  update CHANGELOG
  update CHANGELOG
  update CHANGELOG
  terraform: don't panic on input for bad default type [hashicorpGH-1344]
  helper/ssh: add random number to script [hashicorpGH-1545]
  Allow using deprecated security_groups in NI spec
  provider/aws: Fix issue when creating ELB with no tags
  Refresh state for deleted s3 bucket correctly
  Added Docker links support to the docker_container resource.
  providers/aws: check allocationId only if it's vpc, fixes hashicorp#1345
  • Loading branch information
marvinpinto committed Apr 20, 2015
2 parents 7e8e70a + 97482f8 commit 07c8f3a
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 10 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

IMPROVEMENTS:

* **New config function: `length`** - Get the length of a string or a list.
* **New config function: `length`** - Get the length of a string or a list.
Useful in conjunction with `split`. [GH-1495]
* core: Improve error message on diff mismatch [GH-1501]
* provisioner/file: expand `~` in source path [GH-1569]
* core: Improve error message on diff mismatch [GH-1501]
* provisioner/file: expand `~` in source path [GH-1569]
* provider/docker: `docker_container` can specify links [GH-1564]

BUG FIXES:

Expand All @@ -17,9 +18,14 @@ BUG FIXES:
edge cases around matching prefixes, which could cause cycles [GH-1527]
* core: fix issue causing diff mismatch errors in certain scenarios during
resource replacement [GH-1515]
* core: don't panic if variable default type is invalid [GH-1344]
* command: remote states with uppercase types work [GH-1356]
* provider/aws: launch configuration ID set after create success [GH-1518]
* provider/aws: manually deleted S3 buckets are refreshed properly [GH-1574]
* provider/aws: only check for EIP allocation ID in VPC [GH-1555]
* provider/openstack: region config is not required [GH-1441]
* provisioner/remote-exec: add random number to uploaded script path so
that parallel provisions work [GH-1588]

## 0.4.2 (April 10, 2015)

Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {

// Verify AWS returned our EIP
if len(describeAddresses.Addresses) != 1 ||
*describeAddresses.Addresses[0].AllocationID != id ||
(domain == "vpc" && *describeAddresses.Addresses[0].AllocationID != id) ||
*describeAddresses.Addresses[0].PublicIP != id {
if err != nil {
return fmt.Errorf("Unable to find EIP: %#v", describeAddresses.Addresses)
Expand Down
1 change: 1 addition & 0 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
AssociatePublicIPAddress: aws.Boolean(associatePublicIPAddress),
DeviceIndex: aws.Long(int64(0)),
SubnetID: aws.String(subnetID),
Groups: groups,
}

if v, ok := d.GetOk("private_ip"); ok {
Expand Down
8 changes: 7 additions & 1 deletion builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
Bucket: aws.String(d.Id()),
})
if err != nil {
return err
if awsError, ok := err.(aws.APIError); ok && awsError.StatusCode == 404 {
d.SetId("")
} else {
// some of the AWS SDK's errors can be empty strings, so let's add
// some additional context.
return fmt.Errorf("error reading S3 bucket \"%s\": %s", d.Id(), err)
}
}

tagSet, err := getTagSetS3(s3conn, d.Id())
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsELB.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func diffTagsELB(oldTags, newTags []*elb.Tag) ([]*elb.Tag, []*elb.Tag) {

// tagsFromMap returns the tags for the given map of data.
func tagsFromMapELB(m map[string]interface{}) []*elb.Tag {
result := make([]*elb.Tag, 0, len(m))
var result []*elb.Tag
for k, v := range m {
result = append(result, &elb.Tag{
Key: aws.String(k),
Expand Down
8 changes: 8 additions & 0 deletions builtin/providers/docker/resource_docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ func resourceDockerContainer() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash,
},

"links": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash,
},
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions builtin/providers/docker/resource_docker_container_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
hostConfig.DNS = stringSetToStringSlice(v.(*schema.Set))
}

if v, ok := d.GetOk("links"); ok {
hostConfig.Links = stringSetToStringSlice(v.(*schema.Set))
}

if err := client.StartContainer(retContainer.ID, hostConfig); err != nil {
return fmt.Errorf("Unable to start container: %s", err)
}
Expand Down
8 changes: 5 additions & 3 deletions builtin/provisioners/remote-exec/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ func (p *ResourceProvisioner) runScripts(
go p.copyOutput(o, errR, errDoneCh)

err := retryFunc(conf.TimeoutVal, func() error {
if err := comm.Upload(conf.ScriptPath, script); err != nil {
remotePath := conf.RemotePath()

if err := comm.Upload(remotePath, script); err != nil {
return fmt.Errorf("Failed to upload script: %v", err)
}
cmd = &helper.RemoteCmd{
Command: fmt.Sprintf("chmod 0777 %s", conf.ScriptPath),
Command: fmt.Sprintf("chmod 0777 %s", remotePath),
}
if err := comm.Start(cmd); err != nil {
return fmt.Errorf(
Expand All @@ -227,7 +229,7 @@ func (p *ResourceProvisioner) runScripts(
cmd.Wait()

cmd = &helper.RemoteCmd{
Command: conf.ScriptPath,
Command: remotePath,
Stdout: outW,
Stderr: errW,
}
Expand Down
11 changes: 10 additions & 1 deletion helper/ssh/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform/terraform"
Expand All @@ -25,7 +28,7 @@ const (

// DefaultScriptPath is used as the path to copy the file to
// for remote execution if not provided otherwise.
DefaultScriptPath = "/tmp/script.sh"
DefaultScriptPath = "/tmp/script_%RAND%.sh"

// DefaultTimeout is used if there is no timeout given
DefaultTimeout = 5 * time.Minute
Expand All @@ -46,6 +49,12 @@ type SSHConfig struct {
TimeoutVal time.Duration `mapstructure:"-"`
}

func (c *SSHConfig) RemotePath() string {
return strings.Replace(
c.ScriptPath, "%RAND%",
strconv.FormatInt(int64(rand.Int31()), 10), -1)
}

// VerifySSH is used to verify the ConnInfo is usable by remote-exec
func VerifySSH(s *terraform.InstanceState) error {
connType := s.Ephemeral.ConnInfo["type"]
Expand Down
30 changes: 30 additions & 0 deletions helper/ssh/provisioner_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
package ssh

import (
"regexp"
"testing"

"github.com/hashicorp/terraform/terraform"
)

func TestSSHConfig_RemotePath(t *testing.T) {
cases := []struct {
Input string
Pattern string
}{
{
"/tmp/script.sh",
`^/tmp/script\.sh$`,
},
{
"/tmp/script_%RAND%.sh",
`^/tmp/script_(\d+)\.sh$`,
},
}

for _, tc := range cases {
config := &SSHConfig{ScriptPath: tc.Input}
output := config.RemotePath()

match, err := regexp.Match(tc.Pattern, []byte(output))
if err != nil {
t.Fatalf("bad: %s\n\nerr: %s", tc.Input, err)
}
if !match {
t.Fatalf("bad: %s\n\n%s", tc.Input, output)
}
}
}

func TestResourceProvider_verifySSH(t *testing.T) {
r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
Expand Down
2 changes: 2 additions & 0 deletions terraform/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (c *Context) Input(mode InputMode) error {

v := m[n]
switch v.Type() {
case config.VariableTypeUnknown:
continue
case config.VariableTypeMap:
continue
case config.VariableTypeString:
Expand Down
22 changes: 22 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,28 @@ func TestContext2Input(t *testing.T) {
}
}

func TestContext2Input_badVarDefault(t *testing.T) {
m := testModule(t, "input-bad-var-default")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})

p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
c.Config["foo"] = "bar"
return c, nil
}

if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestContext2Input_provider(t *testing.T) {
m := testModule(t, "input-provider")
p := testProvider("aws")
Expand Down
5 changes: 5 additions & 0 deletions terraform/test-fixtures/input-bad-var-default/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "test" {
default {
l = [1, 2, 3]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The following arguments are supported:
container.
* `dns` - (Optional, set of strings) Set of DNS servers.
* `env` - (Optional, set of strings) Environmental variables to set.
* `links` - (Optional, set of strings) Set of links for link based
connectivity between containers that are running on the same host.
* `hostname` - (Optional, string) Hostname of the container.
* `domainname` - (Optional, string) Domain name of the container.
* `must_run` - (Optional, bool) If true, then the Docker container will be
Expand Down

0 comments on commit 07c8f3a

Please sign in to comment.