Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix athena db reader #19765

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19765.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_athena_database: Read the database name from the `AwsDataCatalog`
```
32 changes: 4 additions & 28 deletions aws/resource_aws_athena_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ func resourceAwsAthenaDatabaseCreate(d *schema.ResourceData, meta interface{}) e
func resourceAwsAthenaDatabaseRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).athenaconn

input := &athena.StartQueryExecutionInput{
QueryString: aws.String("show databases;"),
ResultConfiguration: expandAthenaResultConfiguration(d.Get("bucket").(string), d.Get("encryption_configuration").([]interface{})),
input := &athena.GetDatabaseInput{
DatabaseName: aws.String(d.Get("name").(string)),
CatalogName: aws.String("AwsDataCatalog"),
}

resp, err := conn.StartQueryExecution(input)
_, err := conn.GetDatabase(input)
if err != nil {
return err
}

if err := executeAndExpectMatchingRow(*resp.QueryExecutionId, d.Get("name").(string), conn); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -170,25 +165,6 @@ func executeAndExpectNoRowsWhenCreate(qeid string, conn *athena.Athena) error {
return nil
}

func executeAndExpectMatchingRow(qeid string, dbName string, conn *athena.Athena) error {
rs, err := queryExecutionResult(qeid, conn)
if err != nil {
return err
}
for _, row := range rs.Rows {
for _, datum := range row.Data {
if datum == nil {
continue
}

if aws.StringValue(datum.VarCharValue) == dbName {
return nil
}
}
}
return fmt.Errorf("Athena not found database: %s, query result: %s", dbName, flattenAthenaResultSet(rs))
}

func executeAndExpectNoRowsWhenDrop(qeid string, conn *athena.Athena) error {
rs, err := queryExecutionResult(qeid, conn)
if err != nil {
Expand Down