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

Add Route 53 Resolver rule and rule association resources #7799

Merged
merged 7 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ func Provider() terraform.ResourceProvider {
"aws_route53_zone": resourceAwsRoute53Zone(),
"aws_route53_health_check": resourceAwsRoute53HealthCheck(),
"aws_route53_resolver_endpoint": resourceAwsRoute53ResolverEndpoint(),
"aws_route53_resolver_rule_association": resourceAwsRoute53ResolverRuleAssociation(),
"aws_route53_resolver_rule": resourceAwsRoute53ResolverRule(),
"aws_route": resourceAwsRoute(),
"aws_route_table": resourceAwsRouteTable(),
"aws_default_route_table": resourceAwsDefaultRouteTable(),
Expand Down
31 changes: 17 additions & 14 deletions aws/resource_aws_route53_resolver_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func resourceAwsRoute53ResolverEndpoint() *schema.Resource {
},
},
},
Set: route53ResolverHashIPAddress,
Set: route53ResolverEndpointHashIpAddress,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed route53ResolverHashIPAddress to route53ResolverEndpointHashIpAddress as it applies only to aws_route53_resolver_endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit on name route53ResolverEndpointIpAddressHash

},

"security_group_ids": {
Expand All @@ -78,7 +78,7 @@ func resourceAwsRoute53ResolverEndpoint() *schema.Resource {
"name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateRoute53ResolverEndpointName,
ValidateFunc: validateRoute53ResolverName,
nywilken marked this conversation as resolved.
Show resolved Hide resolved
},

"tags": tagsSchema(),
Expand Down Expand Up @@ -106,12 +106,12 @@ func resourceAwsRoute53ResolverEndpointCreate(d *schema.ResourceData, meta inter
conn := meta.(*AWSClient).route53resolverconn

req := &route53resolver.CreateResolverEndpointInput{
CreatorRequestId: aws.String(resource.PrefixedUniqueId("tf-r53-resolver-")),
CreatorRequestId: aws.String(resource.PrefixedUniqueId("tf-r53-resolver-endpoint-")),
Direction: aws.String(d.Get("direction").(string)),
IpAddresses: expandRoute53ResolverIpAddresses(d.Get("ip_address").(*schema.Set)),
nywilken marked this conversation as resolved.
Show resolved Hide resolved
IpAddresses: expandRoute53ResolverEndpointIpAddresses(d.Get("ip_address").(*schema.Set)),
SecurityGroupIds: expandStringSet(d.Get("security_group_ids").(*schema.Set)),
}
if v, ok := d.GetOk("name"); ok && v.(string) != "" {
if v, ok := d.GetOk("name"); ok {
req.Name = aws.String(v.(string))
}
if v, ok := d.GetOk("tags"); ok && len(v.(map[string]interface{})) > 0 {
Expand Down Expand Up @@ -168,14 +168,14 @@ func resourceAwsRoute53ResolverEndpointRead(d *schema.ResourceData, meta interfa
return fmt.Errorf("error getting Route53 Resolver endpoint (%s) IP addresses: %s", d.Id(), err)
}

ipAddresses = append(ipAddresses, flattenRoute53ResolverIpAddresses(resp.IpAddresses)...)
nywilken marked this conversation as resolved.
Show resolved Hide resolved
ipAddresses = append(ipAddresses, flattenRoute53ResolverEndpointIpAddresses(resp.IpAddresses)...)

if resp.NextToken == nil {
break
}
req.NextToken = resp.NextToken
}
if err := d.Set("ip_address", schema.NewSet(route53ResolverHashIPAddress, ipAddresses)); err != nil {
if err := d.Set("ip_address", schema.NewSet(route53ResolverEndpointHashIpAddress, ipAddresses)); err != nil {
return err
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func resourceAwsRoute53ResolverEndpointUpdate(d *schema.ResourceData, meta inter
for _, v := range add {
_, err := conn.AssociateResolverEndpointIpAddress(&route53resolver.AssociateResolverEndpointIpAddressInput{
ResolverEndpointId: aws.String(d.Id()),
IpAddress: expandRoute53ResolverIpAddressUpdate(v),
IpAddress: expandRoute53ResolverEndpointIpAddressUpdate(v),
})
if err != nil {
return fmt.Errorf("error associating Route53 Resolver endpoint (%s) IP address: %s", d.Id(), err)
Expand All @@ -240,7 +240,7 @@ func resourceAwsRoute53ResolverEndpointUpdate(d *schema.ResourceData, meta inter
for _, v := range del {
_, err := conn.DisassociateResolverEndpointIpAddress(&route53resolver.DisassociateResolverEndpointIpAddressInput{
ResolverEndpointId: aws.String(d.Id()),
IpAddress: expandRoute53ResolverIpAddressUpdate(v),
IpAddress: expandRoute53ResolverEndpointIpAddressUpdate(v),
})
if err != nil {
return fmt.Errorf("error disassociating Route53 Resolver endpoint (%s) IP address: %s", d.Id(), err)
Expand Down Expand Up @@ -273,11 +273,10 @@ func resourceAwsRoute53ResolverEndpointDelete(d *schema.ResourceData, meta inter
_, err := conn.DeleteResolverEndpoint(&route53resolver.DeleteResolverEndpointInput{
ResolverEndpointId: aws.String(d.Id()),
})
if isAWSErr(err, route53resolver.ErrCodeResourceNotFoundException, "") {
return nil
}
if err != nil {
if isAWSErr(err, route53resolver.ErrCodeResourceNotFoundException, "") {
return nil
}

return fmt.Errorf("error deleting Route53 Resolver endpoint (%s): %s", d.Id(), err)
}

Expand All @@ -303,6 +302,10 @@ func route53ResolverEndpointRefresh(conn *route53resolver.Route53Resolver, epId
return nil, "", err
}

if statusMessage := aws.StringValue(resp.ResolverEndpoint.StatusMessage); statusMessage != "" {
log.Printf("[INFO] Route 53 Resolver endpoint (%s) status message: %s", epId, statusMessage)
}

return resp.ResolverEndpoint, aws.StringValue(resp.ResolverEndpoint.Status), nil
}
}
Expand All @@ -323,7 +326,7 @@ func route53ResolverEndpointWaitUntilTargetState(conn *route53resolver.Route53Re
return nil
}

func route53ResolverHashIPAddress(v interface{}) int {
func route53ResolverEndpointHashIpAddress(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["subnet_id"].(string)))
Expand Down
5 changes: 3 additions & 2 deletions aws/resource_aws_route53_resolver_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ func testAccCheckRoute53ResolverEndpointDestroy(s *terraform.State) error {
})
// Verify the error is what we want
if isAWSErr(err, route53resolver.ErrCodeResourceNotFoundException, "") {
return nil
continue
nywilken marked this conversation as resolved.
Show resolved Hide resolved
}
if err != nil {
return err
}
return fmt.Errorf("Route 53 Resolver endpoint still exists: %s", rs.Primary.ID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return error if resolver endpoint still exists.

}

return nil
Expand All @@ -169,7 +170,7 @@ func testAccCheckRoute53ResolverEndpointExists(n string, ep *route53resolver.Res
}

if rs.Primary.ID == "" {
return fmt.Errorf("No Route 53 Resolver Endpoint ID is set")
return fmt.Errorf("No Route 53 Resolver endpoint ID is set")
}

conn := testAccProvider.Meta().(*AWSClient).route53resolverconn
Expand Down
Loading