Skip to content

Commit

Permalink
write schema and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-br committed Apr 4, 2022
1 parent 656d2c9 commit 4eec18f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions env0/data_aws_cost_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func dataAwsCostCredentialsRead(ctx context.Context, d *schema.ResourceData, met
}
}

d.SetId(credentials.Id)
d.Set("name", credentials.Name)
errorWhenWriteData := writeResourceData(credentials, d)
if errorWhenWriteData != nil {
return diag.Errorf("Error:", errorWhenWriteData)
}

return nil
}
Expand Down
6 changes: 4 additions & 2 deletions env0/data_azure_cost_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ func dataAzureCostCredentialsRead(ctx context.Context, d *schema.ResourceData, m
}
}

d.SetId(credentials.Id)
d.Set("name", credentials.Name)
errorWhenWriteData := writeResourceData(credentials, d)
if errorWhenWriteData != nil {
return diag.Errorf("Error:", errorWhenWriteData)
}

return nil
}
Expand Down
14 changes: 8 additions & 6 deletions env0/data_google_cost_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ func dataGoogleCostCredentialsRead(ctx context.Context, d *schema.ResourceData,
}
}

d.SetId(credentials.Id)
d.Set("name", credentials.Name)
errorWhenWriteData := writeResourceData(credentials, d)
if errorWhenWriteData != nil {
return diag.Errorf("Error:", errorWhenWriteData)
}

return nil
}
Expand All @@ -57,7 +59,7 @@ func getGoogleCostCredentialsByName(name interface{}, meta interface{}) (client.
apiClient := meta.(client.ApiClientInterface)
credentialsList, err := apiClient.CloudCredentialsList()
if err != nil {
return client.Credentials{}, diag.Errorf("Could not query GCP Credentials by name: %v", err)
return client.Credentials{}, diag.Errorf("Could not query Google Credentials by name: %v", err)
}

credentialsByNameAndType := make([]client.Credentials, 0)
Expand All @@ -71,7 +73,7 @@ func getGoogleCostCredentialsByName(name interface{}, meta interface{}) (client.
return client.Credentials{}, diag.Errorf("Found multiple Google cost Credentials for name: %s", name)
}
if len(credentialsByNameAndType) == 0 {
return client.Credentials{}, diag.Errorf("Could not find GCP Credentials with name: %s", name)
return client.Credentials{}, diag.Errorf("Could not find Google Credentials with name: %s", name)
}
return credentialsByNameAndType[0], nil
}
Expand All @@ -80,10 +82,10 @@ func getGoogleCostCredentialsById(id string, meta interface{}) (client.Credentia
apiClient := meta.(client.ApiClientInterface)
credentials, err := apiClient.CloudCredentials(id)
if !isValidGoogleCostCredentialsType(credentials.Type) {
return client.Credentials{}, diag.Errorf("Found credentials which are not GCP Credentials: %v", credentials)
return client.Credentials{}, diag.Errorf("Found credentials which are not Google Credentials: %v", credentials)
}
if err != nil {
return client.Credentials{}, diag.Errorf("Could not query GCP Credentials: %v", err)
return client.Credentials{}, diag.Errorf("Could not query Google Credentials: %v", err)
}
return credentials, nil
}
Expand Down

0 comments on commit 4eec18f

Please sign in to comment.