Skip to content

Commit

Permalink
Use 'ConflictsWith' in schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jan 19, 2018
1 parent 9ae96bf commit 6e59b27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
28 changes: 13 additions & 15 deletions aws/data_source_aws_vpc_endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
33 changes: 15 additions & 18 deletions aws/resource_aws_vpc_endpoint_connection_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e59b27

Please sign in to comment.