Skip to content

Commit

Permalink
for data source read fix the order of error check (#123)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <[email protected]>
  • Loading branch information
havetisyan authored Sep 25, 2024
1 parent a55ced0 commit 3666e73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions athenz/data_source_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package athenz

import (
"context"
"github.com/ardielle/ardielle-go/rdl"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/AthenZ/terraform-provider-athenz/client"
"github.com/ardielle/ardielle-go/rdl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -62,12 +62,6 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int
fullResourceName := domainName + SERVICE_SEPARATOR + shortServiceName

service, err := client.GetServiceIdentity(domainName, shortServiceName)
if err := d.Set("description", service.Description); err != nil {
return nil
}
if err := d.Set("public_keys", flattenPublicKeyEntryList(service.PublicKeys)); err != nil {
return nil
}
switch v := err.(type) {
case rdl.ResourceError:
if v.Code == 404 {
Expand All @@ -78,6 +72,14 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int
case rdl.Any:
return diag.FromErr(err)
}

if err := d.Set("description", service.Description); err != nil {
return nil
}
if err := d.Set("public_keys", flattenPublicKeyEntryList(service.PublicKeys)); err != nil {
return nil
}

d.SetId(fullResourceName)
if len(service.Tags) > 0 {
if err = d.Set("tags", flattenTag(service.Tags)); err != nil {
Expand Down
1 change: 0 additions & 1 deletion athenz/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}
service, err := zmsClient.GetServiceIdentity(domainName, serviceName)
//return diag.Errorf("terraform plan resource")

switch v := err.(type) {
case rdl.ResourceError:
Expand Down

0 comments on commit 3666e73

Please sign in to comment.