Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emr_cluster/instance: force emr connection argument for refresh func #1287

Merged
merged 1 commit into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cluster_state", cluster.Status.State)
}

instanceGroups, err := fetchAllEMRInstanceGroups(meta, d.Id())
instanceGroups, err := fetchAllEMRInstanceGroups(emrconn, d.Id())
if err == nil {
coreGroup := findGroup(instanceGroups, "CORE")
if coreGroup != nil {
Expand Down Expand Up @@ -414,7 +414,7 @@ func resourceAwsEMRClusterUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("core_instance_count") {
d.SetPartial("core_instance_count")
log.Printf("[DEBUG] Modify EMR cluster")
groups, err := fetchAllEMRInstanceGroups(meta, d.Id())
groups, err := fetchAllEMRInstanceGroups(conn, d.Id())
if err != nil {
log.Printf("[DEBUG] Error finding all instance groups: %s", err)
return err
Expand Down
14 changes: 7 additions & 7 deletions aws/resource_aws_emr_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func resourceAwsEMRInstanceGroupCreate(d *schema.ResourceData, meta interface{})
}

func resourceAwsEMRInstanceGroupRead(d *schema.ResourceData, meta interface{}) error {
group, err := fetchEMRInstanceGroup(meta, d.Get("cluster_id").(string), d.Id())
conn := meta.(*AWSClient).emrconn
group, err := fetchEMRInstanceGroup(conn, d.Get("cluster_id").(string), d.Id())
if err != nil {
switch err {
case emrInstanceGroupNotFound:
Expand Down Expand Up @@ -186,8 +187,7 @@ func resourceAwsEMRInstanceGroupRead(d *schema.ResourceData, meta interface{}) e
return nil
}

func fetchAllEMRInstanceGroups(meta interface{}, clusterId string) ([]*emr.InstanceGroup, error) {
conn := meta.(*AWSClient).emrconn
func fetchAllEMRInstanceGroups(conn *emr.EMR, clusterId string) ([]*emr.InstanceGroup, error) {
req := &emr.ListInstanceGroupsInput{
ClusterId: aws.String(clusterId),
}
Expand Down Expand Up @@ -221,8 +221,8 @@ func fetchAllEMRInstanceGroups(meta interface{}, clusterId string) ([]*emr.Insta
return groups, nil
}

func fetchEMRInstanceGroup(meta interface{}, clusterId, groupId string) (*emr.InstanceGroup, error) {
groups, err := fetchAllEMRInstanceGroups(meta, clusterId)
func fetchEMRInstanceGroup(conn *emr.EMR, clusterId, groupId string) (*emr.InstanceGroup, error) {
groups, err := fetchAllEMRInstanceGroups(conn, clusterId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -280,9 +280,9 @@ func resourceAwsEMRInstanceGroupUpdate(d *schema.ResourceData, meta interface{})
return resourceAwsEMRInstanceGroupRead(d, meta)
}

func instanceGroupStateRefresh(meta interface{}, clusterID, igID string) resource.StateRefreshFunc {
func instanceGroupStateRefresh(conn *emr.EMR, clusterID, igID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
group, err := fetchEMRInstanceGroup(meta, clusterID, igID)
group, err := fetchEMRInstanceGroup(conn, clusterID, igID)
if err != nil {
return nil, "Not Found", err
}
Expand Down
40 changes: 38 additions & 2 deletions aws/resource_aws_emr_instance_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ func TestAccAWSEMRInstanceGroup_basic(t *testing.T) {
})
}

// Confirm we can scale down the instance count. Regression test for https://github.com/terraform-providers/terraform-provider-aws/issues/1264
func TestAccAWSEMRInstanceGroup_zero_count(t *testing.T) {
var ig emr.InstanceGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEmrInstanceGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEmrInstanceGroupConfig(rInt),
Check: testAccCheckAWSEmrInstanceGroupExists("aws_emr_instance_group.task", &ig),
},
{
Config: testAccAWSEmrInstanceGroupConfig_zero_count(rInt),
Check: testAccCheckAWSEmrInstanceGroupExists("aws_emr_instance_group.task", &ig),
},
},
})
}

func TestAccAWSEMRInstanceGroup_ebsBasic(t *testing.T) {
var ig emr.InstanceGroup
rInt := acctest.RandInt()
Expand Down Expand Up @@ -93,7 +114,8 @@ func testAccCheckAWSEmrInstanceGroupExists(n string, v *emr.InstanceGroup) resou
return fmt.Errorf("No task group id set")
}
meta := testAccProvider.Meta()
g, err := fetchEMRInstanceGroup(meta, rs.Primary.Attributes["cluster_id"], rs.Primary.ID)
conn := meta.(*AWSClient).emrconn
g, err := fetchEMRInstanceGroup(conn, rs.Primary.Attributes["cluster_id"], rs.Primary.ID)
if err != nil {
return fmt.Errorf("EMR error: %v", err)
}
Expand Down Expand Up @@ -176,6 +198,10 @@ resource "aws_security_group" "allow_all" {
resource "aws_vpc" "main" {
cidr_block = "168.31.0.0/16"
enable_dns_hostnames = true

tags {
Name = "tf_acc_emr_tests"
}
}

resource "aws_subnet" "main" {
Expand Down Expand Up @@ -375,7 +401,17 @@ func testAccAWSEmrInstanceGroupConfig(r int) string {
resource "aws_emr_instance_group" "task" {
cluster_id = "${aws_emr_cluster.tf-test-cluster.id}"
instance_count = 1
instance_type = "m3.xlarge"
instance_type = "m1.small"
}
`, r, r, r, r, r, r)
}

func testAccAWSEmrInstanceGroupConfig_zero_count(r int) string {
return fmt.Sprintf(testAccAWSEmrInstanceGroupBase+`
resource "aws_emr_instance_group" "task" {
cluster_id = "${aws_emr_cluster.tf-test-cluster.id}"
instance_count = 0
instance_type = "m1.small"
}
`, r, r, r, r, r, r)
}
Expand Down