diff --git a/aws/data_source_aws_vpc_endpoint_service.go b/aws/data_source_aws_vpc_endpoint_service.go index e279d80345d..428747cca61 100644 --- a/aws/data_source_aws_vpc_endpoint_service.go +++ b/aws/data_source_aws_vpc_endpoint_service.go @@ -17,13 +17,15 @@ func dataSourceAwsVpcEndpointService() *schema.Resource { Schema: map[string]*schema.Schema{ "service": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"service_name"}, }, "service_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"service"}, }, "service_type": { Type: schema.TypeString, @@ -64,18 +66,14 @@ func dataSourceAwsVpcEndpointService() *schema.Resource { func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - svc, svcOk := d.GetOk("service") - svcName, svcNameOk := d.GetOk("service_name") - if svcOk == svcNameOk { - return fmt.Errorf( - "One of ['service', 'service_name'] must be set to query VPC Endpoint Services") - } - var serviceName string - if svcNameOk { - serviceName = svcName.(string) + if v, ok := d.GetOk("service_name"); ok { + serviceName = v.(string) + } else if v, ok := d.GetOk("service"); ok { + serviceName = fmt.Sprintf("com.amazonaws.%s.%s", meta.(*AWSClient).region, v.(string)) } else { - serviceName = fmt.Sprintf("com.amazonaws.%s.%s", meta.(*AWSClient).region, svc.(string)) + return fmt.Errorf( + "One of ['service', 'service_name'] must be set to query VPC Endpoint Services") } req := &ec2.DescribeVpcEndpointServicesInput{ diff --git a/aws/resource_aws_vpc_endpoint_connection_notification.go b/aws/resource_aws_vpc_endpoint_connection_notification.go index 19e4b1dbfd6..be6f990357a 100644 --- a/aws/resource_aws_vpc_endpoint_connection_notification.go +++ b/aws/resource_aws_vpc_endpoint_connection_notification.go @@ -21,14 +21,16 @@ func resourceAwsVpcEndpointConnectionNotification() *schema.Resource { Schema: map[string]*schema.Schema{ "vpc_endpoint_service_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"vpc_endpoint_id"}, }, "vpc_endpoint_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"vpc_endpoint_service_id"}, }, "connection_notification_arn": { Type: schema.TypeString, @@ -57,22 +59,17 @@ func resourceAwsVpcEndpointConnectionNotification() *schema.Resource { func resourceAwsVpcEndpointConnectionNotificationCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - svcId, svcIdOk := d.GetOk("vpc_endpoint_service_id") - vpceId, vpceIdOk := d.GetOk("vpc_endpoint_id") - if svcIdOk == vpceIdOk { - return fmt.Errorf( - "One of ['vpc_endpoint_service_id', 'vpc_endpoint_id'] must be set to create a VPC Endpoint connection notification") - } - req := &ec2.CreateVpcEndpointConnectionNotificationInput{ ConnectionNotificationArn: aws.String(d.Get("connection_notification_arn").(string)), ConnectionEvents: expandStringSet(d.Get("connection_events").(*schema.Set)), } - if svcIdOk { - req.ServiceId = aws.String(svcId.(string)) - } - if vpceIdOk { - req.VpcEndpointId = aws.String(vpceId.(string)) + if v, ok := d.GetOk("vpc_endpoint_service_id"); ok { + req.ServiceId = aws.String(v.(string)) + } else if v, ok := d.GetOk("vpc_endpoint_id"); ok { + req.VpcEndpointId = aws.String(v.(string)) + } else { + return fmt.Errorf( + "One of ['vpc_endpoint_service_id', 'vpc_endpoint_id'] must be set to create a VPC Endpoint connection notification") } log.Printf("[DEBUG] Creating VPC Endpoint connection notification: %#v", req)