-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Support VPC configuration of aws_elasticsearch_domain resources. #1958
Changes from 5 commits
1a2d978
f57cd53
54d14e1
4b3dd70
737d763
d4945cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,62 @@ func TestAccAWSElasticSearchDomain_complex(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSElasticSearchDomain_vpc(t *testing.T) { | ||
var domain elasticsearch.ElasticsearchDomainStatus | ||
ri := acctest.RandInt() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckESDomainDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccESDomainConfig_vpc(ri), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSElasticSearchDomain_vpc_update(t *testing.T) { | ||
var domain elasticsearch.ElasticsearchDomainStatus | ||
ri := acctest.RandInt() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckESDomainDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccESDomainConfig_vpc_update(ri, false), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain), | ||
testAccCheckESNumberOfSecurityGroups(1, &domain), | ||
), | ||
}, | ||
{ | ||
Config: testAccESDomainConfig_vpc_update(ri, true), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain), | ||
testAccCheckESNumberOfSecurityGroups(2, &domain), | ||
), | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add another step, where we would update the VPC configuration, so that we ensure the update works as expected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ninir Yeah, I can do that, once I sort the larger IAM problem for the test (update re: that coming next). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disregard "larger IAM problem", I figured it out. 🎉 |
||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckESNumberOfSecurityGroups(numberOfSecurityGroups int, status *elasticsearch.ElasticsearchDomainStatus) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
count := len(status.VPCOptions.SecurityGroupIds) | ||
if count != numberOfSecurityGroups { | ||
return fmt.Errorf("Number of security groups differ. Given: %d, Expected: %d", count, numberOfSecurityGroups) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func TestAccAWSElasticSearchDomain_policy(t *testing.T) { | ||
var domain elasticsearch.ElasticsearchDomainStatus | ||
|
||
|
@@ -448,3 +504,126 @@ resource "aws_elasticsearch_domain" "example" { | |
} | ||
`, randInt) | ||
} | ||
|
||
func testAccESDomainConfig_vpc(randInt int) string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
resource "aws_vpc" "elasticsearch_in_vpc" { | ||
cidr_block = "192.168.0.0/22" | ||
} | ||
|
||
resource "aws_subnet" "first" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[0]}" | ||
cidr_block = "192.168.0.0/24" | ||
} | ||
|
||
resource "aws_subnet" "second" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[1]}" | ||
cidr_block = "192.168.1.0/24" | ||
} | ||
|
||
resource "aws_security_group" "first" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid sharing any resources and allow running multiple tests in parallel do you mind building custom VPC & subnets here, instead of creating default ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done & re-running this test as I write this. It hasn't completed yet, but it brought up the VPC and subnets and SGs, and the ES domain is creating, so I have very high confidence the tear-down will work. :-) |
||
|
||
resource "aws_security_group" "second" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
} | ||
|
||
resource "aws_elasticsearch_domain" "example" { | ||
domain_name = "tf-test-%d" | ||
|
||
ebs_options { | ||
ebs_enabled = false | ||
} | ||
|
||
cluster_config { | ||
instance_count = 2 | ||
zone_awareness_enabled = true | ||
instance_type = "r3.large.elasticsearch" | ||
} | ||
|
||
vpc_options { | ||
security_group_ids = ["${aws_security_group.first.id}", "${aws_security_group.second.id}"] | ||
subnet_ids = ["${aws_subnet.first.id}", "${aws_subnet.second.id}"] | ||
} | ||
} | ||
`, randInt) | ||
} | ||
|
||
func testAccESDomainConfig_vpc_update(randInt int, update bool) string { | ||
var sg_ids, subnet_string string | ||
if update { | ||
sg_ids = "${aws_security_group.first.id}\", \"${aws_security_group.second.id}" | ||
subnet_string = "second" | ||
} else { | ||
sg_ids = "${aws_security_group.first.id}" | ||
subnet_string = "first" | ||
} | ||
|
||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
resource "aws_vpc" "elasticsearch_in_vpc" { | ||
cidr_block = "192.168.0.0/22" | ||
} | ||
|
||
resource "aws_subnet" "az1_first" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[0]}" | ||
cidr_block = "192.168.0.0/24" | ||
} | ||
|
||
resource "aws_subnet" "az2_first" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[1]}" | ||
cidr_block = "192.168.1.0/24" | ||
} | ||
|
||
resource "aws_subnet" "az1_second" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[0]}" | ||
cidr_block = "192.168.2.0/24" | ||
} | ||
|
||
resource "aws_subnet" "az2_second" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
availability_zone = "${data.aws_availability_zones.available.names[1]}" | ||
cidr_block = "192.168.3.0/24" | ||
} | ||
|
||
resource "aws_security_group" "first" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
} | ||
|
||
resource "aws_security_group" "second" { | ||
vpc_id = "${aws_vpc.elasticsearch_in_vpc.id}" | ||
} | ||
|
||
resource "aws_elasticsearch_domain" "example" { | ||
domain_name = "tf-test-%d" | ||
|
||
ebs_options { | ||
ebs_enabled = false | ||
} | ||
|
||
cluster_config { | ||
instance_count = 2 | ||
zone_awareness_enabled = true | ||
instance_type = "r3.large.elasticsearch" | ||
} | ||
|
||
vpc_options { | ||
security_group_ids = ["%s"] | ||
subnet_ids = ["${aws_subnet.az1_%s.id}", "${aws_subnet.az2_%s.id}"] | ||
} | ||
} | ||
`, randInt, sg_ids, subnet_string, subnet_string) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first thought this is a bad idea, until I took time and read http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html#es-enabling-slr 😢
I wish there was an ES service method to do this... but that's not the reality, so good call 👍