Skip to content

Commit

Permalink
Merge pull request #1 from terraform-providers/master
Browse files Browse the repository at this point in the history
merging head fork
  • Loading branch information
Dan Jones authored Sep 6, 2018
2 parents 15035b1 + 4235dc3 commit f1be555
Show file tree
Hide file tree
Showing 66 changed files with 3,512 additions and 1,052 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## 1.35.0 (Unreleased)
## 1.36.0 (Unreleased)
## 1.35.0 (September 06, 2018)

ENHANCEMENTS:

* resource/aws_iam_role: Allow empty string (`""`) value for `permissions_boundary` argument [GH-5740]
* data-source/aws_eks_cluster: Add `platform_version` attribute ([#5797](https://github.com/terraform-providers/terraform-provider-aws/issues/5797))
* resource/aws_eks_cluster: Add `platform_version` attribute ([#5797](https://github.com/terraform-providers/terraform-provider-aws/issues/5797))
* resource/aws_lambda_function: Allow empty lists for `vpc_config` `security_group_ids` and `subnet_ids` arguments to unconfigure VPC ([#1341](https://github.com/terraform-providers/terraform-provider-aws/issues/1341))
* resource/aws_iam_role: Allow empty string (`""`) value for `permissions_boundary` argument ([#5740](https://github.com/terraform-providers/terraform-provider-aws/issues/5740))

BUG FIXES:

* resource/aws_ecr_repository: Use `RepositoryUri` instead of our building our own URI for the `repository_url` attribute (AWS China fix) [GH-5748]
* resource/aws_ecr_repository: Use `RepositoryUri` instead of our building our own URI for the `repository_url` attribute (AWS China fix) ([#5748](https://github.com/terraform-providers/terraform-provider-aws/issues/5748))
* resource/aws_lambda_function: Properly handle `vpc_config` removal ([#5798](https://github.com/terraform-providers/terraform-provider-aws/issues/5798))
* resource/aws_redshift_cluster: Properly force new resource when updating `availability_zone` argument ([#5758](https://github.com/terraform-providers/terraform-provider-aws/issues/5758))

## 1.34.0 (August 30, 2018)

Expand Down
12 changes: 11 additions & 1 deletion aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,20 @@ func (c *Config) Client() (interface{}, error) {
var err error
client.accountid, client.partition, err = GetAccountIDAndPartition(client.iamconn, client.stsconn, cp.ProviderName)
if err != nil {
return nil, fmt.Errorf("Failed getting account information via all available methods. Errors: %s", err)
// DEPRECATED: Next major version of the provider should return the error instead of logging
// if skip_request_account_id is not enabled.
log.Printf("[WARN] %s", fmt.Sprintf(
"AWS account ID not previously found and failed retrieving via all available methods. "+
"This will return an error in the next major version of the AWS provider. "+
"See https://www.terraform.io/docs/providers/aws/index.html#skip_requesting_account_id for workaround and implications. "+
"Errors: %s", err))
}
}

if client.accountid == "" {
log.Printf("[WARN] AWS account ID not found for provider. See https://www.terraform.io/docs/providers/aws/index.html#skip_requesting_account_id for implications.")
}

authErr := c.ValidateAccountId(client.accountid)
if authErr != nil {
return nil, authErr
Expand Down
5 changes: 5 additions & 0 deletions aws/data_source_aws_eks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func dataSourceAwsEksCluster() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},
"platform_version": {
Type: schema.TypeString,
Computed: true,
},
"role_arn": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -110,6 +114,7 @@ func dataSourceAwsEksClusterRead(d *schema.ResourceData, meta interface{}) error
d.Set("created_at", aws.TimeValue(cluster.CreatedAt).String())
d.Set("endpoint", cluster.Endpoint)
d.Set("name", cluster.Name)
d.Set("platform_version", cluster.PlatformVersion)
d.Set("role_arn", cluster.RoleArn)
d.Set("version", cluster.Version)

Expand Down
2 changes: 2 additions & 0 deletions aws/data_source_aws_eks_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
Expand All @@ -26,6 +27,7 @@ func TestAccAWSEksClusterDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "certificate_authority.0.data", dataSourceResourceName, "certificate_authority.0.data"),
resource.TestCheckResourceAttrPair(resourceName, "created_at", dataSourceResourceName, "created_at"),
resource.TestCheckResourceAttrPair(resourceName, "endpoint", dataSourceResourceName, "endpoint"),
resource.TestMatchResourceAttr(resourceName, "platform_version", regexp.MustCompile(`^eks\.\d+$`)),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", dataSourceResourceName, "role_arn"),
resource.TestCheckResourceAttrPair(resourceName, "version", dataSourceResourceName, "version"),
resource.TestCheckResourceAttr(dataSourceResourceName, "vpc_config.#", "1"),
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_eks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func resourceAwsEksCluster() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},
"platform_version": {
Type: schema.TypeString,
Computed: true,
},
"role_arn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -195,6 +199,7 @@ func resourceAwsEksClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("created_at", aws.TimeValue(cluster.CreatedAt).String())
d.Set("endpoint", cluster.Endpoint)
d.Set("name", cluster.Name)
d.Set("platform_version", cluster.PlatformVersion)
d.Set("role_arn", cluster.RoleArn)
d.Set("version", cluster.Version)

Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_eks_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestAccAWSEksCluster_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "certificate_authority.0.data"),
resource.TestMatchResourceAttr(resourceName, "endpoint", regexp.MustCompile(`^https://`)),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestMatchResourceAttr(resourceName, "platform_version", regexp.MustCompile(`^eks\.\d+$`)),
resource.TestMatchResourceAttr(resourceName, "role_arn", regexp.MustCompile(fmt.Sprintf("%s$", rName))),
resource.TestMatchResourceAttr(resourceName, "version", regexp.MustCompile(`^\d+\.\d+$`)),
resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"),
Expand Down
75 changes: 31 additions & 44 deletions aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ func resourceAwsLambdaFunction() *schema.Resource {
},
},
},

// Suppress diffs if the VPC configuration is provided, but empty
// which is a valid Lambda function configuration. e.g.
// vpc_config {
// security_group_ids = []
// subnet_ids = []
// }
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Id() == "" || old == "1" || new == "0" {
return false
}

if d.HasChange("vpc_config.0.security_group_ids") || d.HasChange("vpc_config.0.subnet_ids") {
return false
}

return true
},
},
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -305,30 +323,12 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e
}
}

if v, ok := d.GetOk("vpc_config"); ok {

configs := v.([]interface{})
config, ok := configs[0].(map[string]interface{})

if !ok {
return errors.New("vpc_config is <nil>")
}

if config != nil {
var subnetIds []*string
for _, id := range config["subnet_ids"].(*schema.Set).List() {
subnetIds = append(subnetIds, aws.String(id.(string)))
}

var securityGroupIds []*string
for _, id := range config["security_group_ids"].(*schema.Set).List() {
securityGroupIds = append(securityGroupIds, aws.String(id.(string)))
}
if v, ok := d.GetOk("vpc_config"); ok && len(v.([]interface{})) > 0 {
config := v.([]interface{})[0].(map[string]interface{})

params.VpcConfig = &lambda.VpcConfig{
SubnetIds: subnetIds,
SecurityGroupIds: securityGroupIds,
}
params.VpcConfig = &lambda.VpcConfig{
SecurityGroupIds: expandStringSet(config["security_group_ids"].(*schema.Set)),
SubnetIds: expandStringSet(config["subnet_ids"].(*schema.Set)),
}
}

Expand Down Expand Up @@ -680,29 +680,16 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
}
}
if d.HasChange("vpc_config") {
vpcConfigRaw := d.Get("vpc_config").([]interface{})
vpcConfig, ok := vpcConfigRaw[0].(map[string]interface{})
if !ok {
return errors.New("vpc_config is <nil>")
configReq.VpcConfig = &lambda.VpcConfig{
SecurityGroupIds: []*string{},
SubnetIds: []*string{},
}

if vpcConfig != nil {
var subnetIds []*string
for _, id := range vpcConfig["subnet_ids"].(*schema.Set).List() {
subnetIds = append(subnetIds, aws.String(id.(string)))
}

var securityGroupIds []*string
for _, id := range vpcConfig["security_group_ids"].(*schema.Set).List() {
securityGroupIds = append(securityGroupIds, aws.String(id.(string)))
}

configReq.VpcConfig = &lambda.VpcConfig{
SubnetIds: subnetIds,
SecurityGroupIds: securityGroupIds,
}
configUpdate = true
if v, ok := d.GetOk("vpc_config"); ok && len(v.([]interface{})) > 0 {
vpcConfig := v.([]interface{})[0].(map[string]interface{})
configReq.VpcConfig.SecurityGroupIds = expandStringSet(vpcConfig["security_group_ids"].(*schema.Set))
configReq.VpcConfig.SubnetIds = expandStringSet(vpcConfig["subnet_ids"].(*schema.Set))
}
configUpdate = true
}

if d.HasChange("runtime") {
Expand Down
70 changes: 70 additions & 0 deletions aws/resource_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,35 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) {
})
}

func TestAccAWSLambdaFunction_VPCRemoval(t *testing.T) {
var conf lambda.GetFunctionOutput

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lambda_function.lambda_function_test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigWithVPC(rName, rName, rName, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists(resourceName, rName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"),
),
},
{
Config: testAccAWSLambdaConfigBasic(rName, rName, rName, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists(resourceName, rName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "0"),
),
},
},
})
}

func TestAccAWSLambdaFunction_VPCUpdate(t *testing.T) {
var conf lambda.GetFunctionOutput

Expand Down Expand Up @@ -604,6 +633,31 @@ func TestAccAWSLambdaFunction_VPC_withInvocation(t *testing.T) {
})
}

func TestAccAWSLambdaFunction_EmptyVpcConfig(t *testing.T) {
var conf lambda.GetFunctionOutput

rString := acctest.RandString(8)
funcName := fmt.Sprintf("tf_acc_lambda_func_empty_vpc_config_%s", rString)
policyName := fmt.Sprintf("tf_acc_policy_lambda_func_empty_vpc_config_%s", rString)
roleName := fmt.Sprintf("tf_acc_role_lambda_func_empty_vpc_config_%s", rString)
sgName := fmt.Sprintf("tf_acc_sg_lambda_func_empty_vpc_config_%s", rString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigWithEmptyVpcConfig(funcName, policyName, roleName, sgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.test", funcName, &conf),
resource.TestCheckResourceAttr("aws_lambda_function.test", "vpc_config.#", "0"),
),
},
},
})
}

func TestAccAWSLambdaFunction_s3(t *testing.T) {
var conf lambda.GetFunctionOutput

Expand Down Expand Up @@ -1688,6 +1742,22 @@ resource "aws_security_group" "sg_for_lambda_2" {
`, funcName, sgName2)
}

func testAccAWSLambdaConfigWithEmptyVpcConfig(funcName, policyName, roleName, sgName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+`
resource "aws_lambda_function" "test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
vpc_config {
subnet_ids = []
security_group_ids = []
}
}`, funcName)
}

func testAccAWSLambdaConfigS3(bucketName, roleName, funcName string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "lambda_bucket" {
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_network_acl_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func resourceAwsNetworkAclRuleCreate(d *schema.ResourceData, meta interface{}) e
}

// Specify additional required fields for ICMP. For the list
// of ICMP codes and types, see: http://www.nthelp.com/icmp.html
// of ICMP codes and types, see: https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
if p == 1 {
params.IcmpTypeCode = &ec2.IcmpTypeCode{}
if v, ok := d.GetOk("icmp_type"); ok {
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_redshift_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func resourceAwsRedshiftCluster() *schema.Resource {
"availability_zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

Expand Down
57 changes: 57 additions & 0 deletions aws/resource_aws_redshift_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,39 @@ func TestAccAWSRedshiftCluster_forceNewUsername(t *testing.T) {
})
}

func TestAccAWSRedshiftCluster_changeAvailabilityZone(t *testing.T) {
var first, second redshift.Cluster

ri := acctest.RandInt()
preConfig := testAccAWSRedshiftClusterConfig_basic(ri)
postConfig := testAccAWSRedshiftClusterConfig_updatedAvailabilityZone(ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &first),
testAccCheckAWSRedshiftClusterAvailabilityZone(&first, "us-west-2a"),
resource.TestCheckResourceAttr("aws_redshift_cluster.default", "availability_zone", "us-west-2a"),
),
},

{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &second),
testAccCheckAWSRedshiftClusterAvailabilityZone(&second, "us-west-2b"),
resource.TestCheckResourceAttr("aws_redshift_cluster.default", "availability_zone", "us-west-2b"),
),
},
},
})
}

func testAccCheckAWSRedshiftClusterDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_redshift_cluster" {
Expand Down Expand Up @@ -629,6 +662,15 @@ func testAccCheckAWSRedshiftClusterMasterUsername(c *redshift.Cluster, value str
}
}

func testAccCheckAWSRedshiftClusterAvailabilityZone(c *redshift.Cluster, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *c.AvailabilityZone != value {
return fmt.Errorf("Expected cluster's AvailabilityZone: %q, given: %q", value, *c.AvailabilityZone)
}
return nil
}
}

func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) {
cases := []struct {
Value string
Expand Down Expand Up @@ -1304,3 +1346,18 @@ resource "aws_redshift_cluster" "default" {
skip_final_snapshot = true
}`, rInt)
}

func testAccAWSRedshiftClusterConfig_updatedAvailabilityZone(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_cluster" "default" {
cluster_identifier = "tf-redshift-cluster-%d"
availability_zone = "us-west-2b"
database_name = "mydb"
master_username = "foo_test"
master_password = "Mustbe8characters"
node_type = "dc1.large"
automated_snapshot_retention_period = 0
allow_version_upgrade = false
skip_final_snapshot = true
}`, rInt)
}
Loading

0 comments on commit f1be555

Please sign in to comment.