forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_data_source.go
107 lines (97 loc) · 2.77 KB
/
service_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package vpclattice
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
// @SDKDataSource("aws_vpclattice_service")
func DataSourceService() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceServiceRead,
Schema: map[string]*schema.Schema{
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"auth_type": {
Type: schema.TypeString,
Computed: true,
},
"certificate_arn": {
Type: schema.TypeString,
Computed: true,
},
"custom_domain_name": {
Type: schema.TypeString,
Computed: true,
},
"dns_entry": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"domain_name": {
Type: schema.TypeString,
Computed: true,
},
"hosted_zone_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"service_identifier": {
Type: schema.TypeString,
Required: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
},
}
}
const (
DSNameService = "Service Data Source"
)
func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).VPCLatticeClient()
service_id := d.Get("service_identifier").(string)
out, err := findServiceByID(ctx, conn, service_id)
if err != nil {
return create.DiagError(names.VPCLattice, create.ErrActionReading, DSNameService, service_id, err)
}
//
// If you don't set the ID, the data source will not be stored in state. In
// fact, that's how a resource can be removed from state - clearing its ID.
//
// If this data source is a companion to a resource, often both will use the
// same ID. Otherwise, the ID will be a unique identifier such as an AWS
// identifier, ARN, or name.
d.SetId(aws.StringValue(out.Id))
d.Set("arn", out.Arn)
d.Set("auth_type", out.AuthType)
d.Set("certificate_arn", out.CertificateArn)
d.Set("custom_domain_name", out.CustomDomainName)
if out.DnsEntry != nil {
if err := d.Set("dns_entry", []interface{}{flattenDNSEntry(out.DnsEntry)}); err != nil {
return diag.Errorf("setting dns_entry: %s", err)
}
} else {
d.Set("dns_entry", nil)
}
d.Set("name", out.Name)
d.Set("status", out.Status)
return nil
}