Skip to content

Commit 0eff4e0

Browse files
author
Marc Boudreau
committed
feedback from review and corrections to make test pass
1 parent 31ab880 commit 0eff4e0

File tree

3 files changed

+105
-99
lines changed

3 files changed

+105
-99
lines changed

aws/data_source_aws_elasticsearch_domain.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package aws
22

33
import (
44
"fmt"
5-
"log"
65

76
"github.com/aws/aws-sdk-go/aws"
87
"github.com/aws/aws-sdk-go/service/elasticsearchservice"
9-
"github.com/hashicorp/errwrap"
108
"github.com/hashicorp/terraform/helper/schema"
119
"github.com/hashicorp/terraform/helper/structure"
1210
)
@@ -121,6 +119,18 @@ func dataSourceAwsElasticSearchDomain() *schema.Resource {
121119
Type: schema.TypeString,
122120
Computed: true,
123121
},
122+
"zone_awareness_config": {
123+
Type: schema.TypeSet,
124+
Computed: true,
125+
Elem: &schema.Resource{
126+
Schema: map[string]*schema.Schema{
127+
"availability_zone_count": {
128+
Type: schema.TypeInt,
129+
Computed: true,
130+
},
131+
},
132+
},
133+
},
124134
"zone_awareness_enabled": {
125135
Type: schema.TypeBool,
126136
Computed: true,
@@ -244,7 +254,7 @@ func dataSourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface
244254

245255
resp, err := esconn.DescribeElasticsearchDomain(req)
246256
if err != nil {
247-
return err
257+
return fmt.Errorf("error querying elasticsearch_domain: %s", err)
248258
}
249259

250260
if resp.DomainStatus == nil {
@@ -258,59 +268,48 @@ func dataSourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface
258268
if ds.AccessPolicies != nil && *ds.AccessPolicies != "" {
259269
policies, err := structure.NormalizeJsonString(*ds.AccessPolicies)
260270
if err != nil {
261-
return errwrap.Wrapf("access policies contain an invalid JSON: {{err}}", err)
271+
return fmt.Errorf("access policies contain an invalid JSON: %s", err)
262272
}
263273
d.Set("access_policies", policies)
264274
}
265275

266-
err = d.Set("advanced_options", pointersMapToStringList(ds.AdvancedOptions))
267-
if err != nil {
268-
return err
276+
if err := d.Set("advanced_options", pointersMapToStringList(ds.AdvancedOptions)); err != nil {
277+
return fmt.Errorf("error setting advanced_options: %s", err)
269278
}
270279

271-
d.Set("arn", *ds.ARN)
280+
d.Set("arn", ds.ARN)
272281
d.Set("domain_id", ds.DomainId)
273282
d.Set("endpoint", ds.Endpoint)
274283
d.Set("kibana_endpoint", getKibanaEndpoint(d))
275284

276-
err = d.Set("ebs_options", flattenESEBSOptions(ds.EBSOptions))
277-
if err != nil {
278-
return err
285+
if err := d.Set("ebs_options", flattenESEBSOptions(ds.EBSOptions)); err != nil {
286+
return fmt.Errorf("error setting ebs_options: %s", err)
279287
}
280288

281-
err = d.Set("encryption_at_rest", flattenESEncryptAtRestOptions(ds.EncryptionAtRestOptions))
282-
if err != nil {
283-
return err
289+
if err := d.Set("encryption_at_rest", flattenESEncryptAtRestOptions(ds.EncryptionAtRestOptions)); err != nil {
290+
return fmt.Errorf("error setting encryption_at_rest: %s", err)
284291
}
285292

286-
err = d.Set("node_to_node_encryption", flattenESNodeToNodeEncryptionOptions(ds.NodeToNodeEncryptionOptions))
287-
if err != nil {
288-
return err
293+
if err := d.Set("node_to_node_encryption", flattenESNodeToNodeEncryptionOptions(ds.NodeToNodeEncryptionOptions)); err != nil {
294+
return fmt.Errorf("error setting node_to_node_encryption: %s", err)
289295
}
290296

291-
err = d.Set("cluster_config", flattenESClusterConfig(ds.ElasticsearchClusterConfig))
292-
if err != nil {
293-
return err
297+
if err := d.Set("cluster_config", flattenESClusterConfig(ds.ElasticsearchClusterConfig)); err != nil {
298+
return fmt.Errorf("error setting cluster_config: %s", err)
294299
}
295300

296-
if ds.SnapshotOptions != nil {
297-
m := map[string]interface{}{}
298-
299-
m["automated_snapshot_start_hour"] = *ds.SnapshotOptions.AutomatedSnapshotStartHour
300-
301-
d.Set("snapshot_options", []map[string]interface{}{m})
301+
if err := d.Set("snapshot_options", flattenESSnapshotOptions(ds.SnapshotOptions)); err != nil {
302+
return fmt.Errorf("error setting snapshot_options: %s", err)
302303
}
303304

304305
if ds.VPCOptions != nil {
305-
err = d.Set("vpc_options", flattenESVPCDerivedInfo(ds.VPCOptions))
306-
if err != nil {
307-
return err
306+
if err := d.Set("vpc_options", flattenESVPCDerivedInfo(ds.VPCOptions)); err != nil {
307+
return fmt.Errorf("error setting vpc_options: %s", err)
308308
}
309309

310310
endpoints := pointersMapToStringList(ds.Endpoints)
311-
err = d.Set("endpoint", endpoints["vpc"])
312-
if err != nil {
313-
return err
311+
if err := d.Set("endpoint", endpoints["vpc"]); err != nil {
312+
return fmt.Errorf("error setting endpoint: %s", err)
314313
}
315314
d.Set("kibana_endpoint", getKibanaEndpoint(d))
316315
if ds.Endpoint != nil {
@@ -342,9 +341,8 @@ func dataSourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface
342341

343342
d.Set("elasticsearch_version", ds.ElasticsearchVersion)
344343

345-
err = d.Set("cognito_options", flattenESCognitoOptions(ds.CognitoOptions))
346-
if err != nil {
347-
return err
344+
if err := d.Set("cognito_options", flattenESCognitoOptions(ds.CognitoOptions)); err != nil {
345+
return fmt.Errorf("error setting cognito_options: %s", err)
348346
}
349347

350348
d.Set("created", ds.Created)
@@ -357,10 +355,12 @@ func dataSourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface
357355
})
358356

359357
if err != nil {
360-
log.Printf("[DEBUG] Error retrieving tags for ARN: %s", *ds.ARN)
358+
return fmt.Errorf("error retrieving tags for elasticsearch_domain: %s", err)
361359
}
362360

363-
d.Set("tags", tagsToMapElasticsearchService(tagResp.TagList))
361+
if err := d.Set("tags", tagsToMapElasticsearchService(tagResp.TagList)); err != nil {
362+
return fmt.Errorf("error setting tags: %s", err)
363+
}
364364

365365
return nil
366366
}

aws/data_source_aws_elasticsearch_domain_test.go

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ import (
1010

1111
func TestAccAWSDataElasticsearchDomain_basic(t *testing.T) {
1212
rInt := acctest.RandInt()
13+
datasourceName := "data.aws_elasticsearch_domain.test"
14+
resourceName := "aws_elasticsearch_domain.test"
1315

14-
resource.Test(t, resource.TestCase{
16+
resource.ParallelTest(t, resource.TestCase{
1517
PreCheck: func() { testAccPreCheck(t) },
1618
Providers: testAccProviders,
1719
Steps: []resource.TestStep{
1820
{
1921
Config: testAccAWSElasticsearchDomainConfigWithDataSource(rInt),
2022
Check: resource.ComposeAggregateTestCheckFunc(
21-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "elasticsearch_version", "1.5"),
22-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.#", "1"),
23-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.instance_type", "t2.micro.elasticsearch"),
24-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.instance_count", "2"),
25-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.dedicated_master_enabled", "false"),
26-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.zone_awareness_enabled", "true"),
27-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.#", "1"),
28-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.ebs_enabled", "true"),
29-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.volume_type", "gp2"),
30-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.volume_size", "20"),
31-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "snapshot_options.#", "1"),
32-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "snapshot_options.0.automated_snapshot_start_hour", "23"),
23+
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch_version", resourceName, "elasticsearch_version"),
24+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.#", resourceName, "cluster_config.#"),
25+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.instance_type", resourceName, "cluster_config.0.instance_type"),
26+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.instance_count", resourceName, "cluster_config.0.instance_count"),
27+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.dedicated_master_enabled", resourceName, "cluster_config.0.dedicated_master_enabled"),
28+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.zone_awareness_enabled", resourceName, "cluster_config.0.zone_awareness_enabled"),
29+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.#", resourceName, "ebs_options.#"),
30+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.ebs_enabled", resourceName, "ebs_options.0.ebs_enabled"),
31+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.volume_type", resourceName, "ebs_options.0.volume_type"),
32+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.volume_size", resourceName, "ebs_options.0.volume_size"),
33+
resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.#", resourceName, "snapshot_options.#"),
34+
resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.0.automated_snapshot_start_hour", resourceName, "snapshot_options.0.automated_snapshot_start_hour"),
3335
),
3436
},
3537
},
@@ -38,29 +40,31 @@ func TestAccAWSDataElasticsearchDomain_basic(t *testing.T) {
3840

3941
func TestAccAWSDataElasticsearchDomain_advanced(t *testing.T) {
4042
rInt := acctest.RandInt()
43+
datasourceName := "data.aws_elasticsearch_domain.test"
44+
resourceName := "aws_elasticsearch_domain.test"
4145

42-
resource.Test(t, resource.TestCase{
46+
resource.ParallelTest(t, resource.TestCase{
4347
PreCheck: func() { testAccPreCheck(t) },
4448
Providers: testAccProviders,
4549
Steps: []resource.TestStep{
4650
{
4751
Config: testAccAWSElasticsearchDomainConfigAdvancedWithDataSource(rInt),
4852
Check: resource.ComposeAggregateTestCheckFunc(
49-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "elasticsearch_version", "1.5"),
50-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.#", "1"),
51-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.instance_type", "t2.micro.elasticsearch"),
52-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.instance_count", "2"),
53-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.dedicated_master_enabled", "false"),
54-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "cluster_config.0.zone_awareness_enabled", "true"),
55-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.#", "1"),
56-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.ebs_enabled", "true"),
57-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.volume_type", "gp2"),
58-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "ebs_options.0.volume_size", "20"),
59-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "snapshot_options.#", "1"),
60-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "snapshot_options.0.automated_snapshot_start_hour", "23"),
61-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "log_publishing_options.#", "1"),
62-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "log_publishing_options.0.log_type", "INDEX_SLOW_LOGS"),
63-
resource.TestCheckResourceAttr("data.aws_elasticsearch_domain.bar", "vpc_options.#", "1"),
53+
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch_version", resourceName, "elasticsearch_version"),
54+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.#", resourceName, "cluster_config.#"),
55+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.instance_type", resourceName, "cluster_config.0.instance_type"),
56+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.instance_count", resourceName, "cluster_config.0.instance_count"),
57+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.dedicated_master_enabled", resourceName, "cluster_config.0.dedicated_master_enabled"),
58+
resource.TestCheckResourceAttrPair(datasourceName, "cluster_config.0.zone_awareness_enabled", resourceName, "cluster_config.0.zone_awareness_enabled"),
59+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.#", resourceName, "ebs_options.#"),
60+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.ebs_enabled", resourceName, "ebs_options.0.ebs_enabled"),
61+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.volume_type", resourceName, "ebs_options.0.volume_type"),
62+
resource.TestCheckResourceAttrPair(datasourceName, "ebs_options.0.volume_size", resourceName, "ebs_options.0.volume_size"),
63+
resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.#", resourceName, "snapshot_options.#"),
64+
resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.0.automated_snapshot_start_hour", resourceName, "snapshot_options.0.automated_snapshot_start_hour"),
65+
resource.TestCheckResourceAttrPair(datasourceName, "log_publishing_options.#", resourceName, "log_publishing_options.#"),
66+
resource.TestCheckResourceAttrPair(datasourceName, "log_publishing_options.0.log_type", resourceName, "log_publishing_options.0.log_type"),
67+
resource.TestCheckResourceAttrPair(datasourceName, "vpc_options.#", resourceName, "vpc_options.#"),
6468
),
6569
},
6670
},
@@ -81,7 +85,7 @@ data "aws_region" "current" {}
8185
8286
data "aws_caller_identity" "current" {}
8387
84-
resource "aws_elasticsearch_domain" "bar" {
88+
resource "aws_elasticsearch_domain" "test" {
8589
domain_name = "${local.random_name}"
8690
elasticsearch_version = "1.5"
8791
@@ -95,7 +99,7 @@ resource "aws_elasticsearch_domain" "bar" {
9599
"Effect": "Allow",
96100
"Resource": "arn:aws:es:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:domain/${local.random_name}/*",
97101
"Condition": {
98-
"IpAddress": {"aws:SourceIp": ["66.193.100.22/32"]}
102+
"IpAddress": {"aws:SourceIp": ["127.0.0.0/8"]}
99103
}
100104
}
101105
]
@@ -105,7 +109,10 @@ POLICY
105109
cluster_config {
106110
instance_type = "t2.micro.elasticsearch"
107111
instance_count = 2
108-
dedicated_master_enabled = false
112+
dedicated_master_enabled = false
113+
zone_awareness_config {
114+
availability_zone_count = 2
115+
}
109116
zone_awareness_enabled = true
110117
}
111118
ebs_options {
@@ -118,8 +125,8 @@ POLICY
118125
}
119126
}
120127
121-
data "aws_elasticsearch_domain" "bar" {
122-
domain_name = "${aws_elasticsearch_domain.bar.domain_name}"
128+
data "aws_elasticsearch_domain" "test" {
129+
domain_name = "${aws_elasticsearch_domain.test.domain_name}"
123130
}
124131
`, rInt)
125132
}
@@ -138,11 +145,11 @@ locals {
138145
random_name = "test-es-%d"
139146
}
140147
141-
resource "aws_cloudwatch_log_group" "bar" {
148+
resource "aws_cloudwatch_log_group" "test" {
142149
name = "${local.random_name}"
143150
}
144151
145-
resource "aws_cloudwatch_log_resource_policy" "bar" {
152+
resource "aws_cloudwatch_log_resource_policy" "test" {
146153
policy_name = "${local.random_name}"
147154
policy_document = <<CONFIG
148155
{
@@ -165,40 +172,40 @@ resource "aws_cloudwatch_log_resource_policy" "bar" {
165172
CONFIG
166173
}
167174
168-
resource "aws_vpc" "bar" {
175+
resource "aws_vpc" "test" {
169176
cidr_block = "10.0.0.0/16"
170177
}
171178
172-
resource "aws_subnet" "bar" {
173-
vpc_id = "${aws_vpc.bar.id}"
179+
resource "aws_subnet" "test" {
180+
vpc_id = "${aws_vpc.test.id}"
174181
cidr_block = "10.0.0.0/24"
175182
}
176183
177-
resource "aws_subnet" "baz" {
178-
vpc_id = "${aws_vpc.bar.id}"
184+
resource "aws_subnet" "test2" {
185+
vpc_id = "${aws_vpc.test.id}"
179186
cidr_block = "10.0.1.0/24"
180187
}
181188
182-
resource "aws_security_group" "bar" {
189+
resource "aws_security_group" "test" {
183190
name = "${local.random_name}"
184-
vpc_id = "${aws_vpc.bar.id}"
191+
vpc_id = "${aws_vpc.test.id}"
185192
}
186193
187-
resource "aws_security_group_rule" "bar" {
194+
resource "aws_security_group_rule" "test" {
188195
type = "ingress"
189196
from_port = 443
190197
to_port = 443
191198
protocol = "tcp"
192199
cidr_blocks = [ "0.0.0.0/0" ]
193200
194-
security_group_id = "${aws_security_group.bar.id}"
201+
security_group_id = "${aws_security_group.test.id}"
195202
}
196203
197-
resource "aws_iam_service_linked_role" "bar" {
204+
resource "aws_iam_service_linked_role" "test" {
198205
aws_service_name = "es.amazonaws.com"
199206
}
200207
201-
resource "aws_elasticsearch_domain" "bar" {
208+
resource "aws_elasticsearch_domain" "test" {
202209
domain_name = "${local.random_name}"
203210
elasticsearch_version = "1.5"
204211
@@ -220,6 +227,9 @@ POLICY
220227
instance_type = "t2.micro.elasticsearch"
221228
instance_count = 2
222229
dedicated_master_enabled = false
230+
zone_awareness_config {
231+
availability_zone_count = 2
232+
}
223233
zone_awareness_enabled = true
224234
}
225235
ebs_options {
@@ -231,30 +241,30 @@ POLICY
231241
automated_snapshot_start_hour = 23
232242
}
233243
log_publishing_options {
234-
cloudwatch_log_group_arn = "${aws_cloudwatch_log_group.bar.arn}"
244+
cloudwatch_log_group_arn = "${aws_cloudwatch_log_group.test.arn}"
235245
log_type = "INDEX_SLOW_LOGS"
236246
}
237247
vpc_options {
238248
security_group_ids = [
239-
"${aws_security_group.bar.id}"
249+
"${aws_security_group.test.id}"
240250
]
241251
subnet_ids = [
242-
"${aws_subnet.bar.id}",
243-
"${aws_subnet.baz.id}"
252+
"${aws_subnet.test.id}",
253+
"${aws_subnet.test2.id}"
244254
]
245255
}
246256
247-
tags {
248-
Domain = "TestDomain"
249-
}
257+
tags = {
258+
Domain = "TestDomain"
259+
}
250260
251-
depends_on = [
252-
"aws_iam_service_linked_role.bar",
261+
depends_on = [
262+
"aws_iam_service_linked_role.test",
253263
]
254264
}
255265
256-
data "aws_elasticsearch_domain" "bar" {
257-
domain_name = "${aws_elasticsearch_domain.bar.domain_name}"
266+
data "aws_elasticsearch_domain" "test" {
267+
domain_name = "${aws_elasticsearch_domain.test.domain_name}"
258268
}
259269
`, rInt)
260270
}

0 commit comments

Comments
 (0)