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

New Resource: AWS Glue Catalog Database #2175

Merged
merged 48 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6afe6ea
Updated vendor folder to include aws glue sdk
Nov 4, 2017
4c79647
Added initial test cases
Nov 4, 2017
29286c5
Added support resources
Nov 4, 2017
cb12806
Implemented glue service and database creation
Nov 4, 2017
da164c4
Expanded test cases to include parameters, description, and location_uri
Nov 5, 2017
b3de1ca
Implemented parameters attribute in database creation
Nov 5, 2017
57a1230
Added documentation
Nov 5, 2017
19ab44c
Added import test
Nov 5, 2017
bb596b8
Fixed import not importing AWS Glue db parameters
Nov 5, 2017
4bfee75
Fixed formatting
Nov 5, 2017
dbfe0e7
Addded missing import documentation
Nov 5, 2017
3fc9052
Removed custom function
Nov 5, 2017
5a603d6
Merge branch 'master' into f-aws-glue
Nov 5, 2017
9a5ed37
Merge branch 'master' into f-aws-glue
Nov 6, 2017
5d717d7
Merge branch 'master' into f-aws-glue
drewsonne Nov 12, 2017
4ebc382
Removed merge artifacts
drewsonne Nov 12, 2017
5fec001
Fixed an error where the incorrect sha was attached to the iam vendor
drewsonne Nov 12, 2017
8744d9b
Removed duplicate glue vendor entry
drewsonne Nov 12, 2017
a0b825d
Merge remote-tracking branch 'origin/master' into f-aws-glue
drewsonne Dec 19, 2017
ec0527e
Removed redundant escapes
drewsonne Dec 19, 2017
5ffc1b0
Removed redundant types
drewsonne Dec 19, 2017
d6de489
Fixed typos
drewsonne Dec 19, 2017
b276648
Use built in terraform err checker
Dec 25, 2017
27d0cb7
Merge branch 'master' into f-aws-glue
Dec 25, 2017
e70c722
Added catalogId field
Dec 26, 2017
886b5ed
Attempted to use a second test step to ensure diff
Dec 26, 2017
429d2a7
Trying to test diff
Dec 26, 2017
6d35a39
Updated docs
Dec 26, 2017
2975924
Merge branch 'master' into f-aws-glue
Dec 26, 2017
935fcf4
Made sure all attributes are set during update
Dec 26, 2017
20faedc
Updated docs
Dec 26, 2017
af18cc6
Fixed inconsistent `ID`
Dec 26, 2017
e5305c3
Fixed incorrect test name
Dec 26, 2017
7511705
Grouped imports ala. gofmt
Dec 26, 2017
efbc83a
Fixed bad fmt
Dec 26, 2017
b8fd125
Test all values of the resource
drewsonne Dec 26, 2017
bb60b99
Fixed bug after changing test helper names
Dec 26, 2017
482db05
Confirm no parameters exist
Dec 26, 2017
d27cc24
Reduce the interface of `createAwsGlueCatalogID`
drewsonne Jan 10, 2018
7701582
Make sure Glue Catalog Database only updates params which are provided.
drewsonne Jan 10, 2018
878627a
Use the common syntac type as noted by @radeksimko
drewsonne Jan 10, 2018
8cdcebc
Check if the DB has been deleted and remove it from the state
drewsonne Jan 10, 2018
419eaa0
Merge branch 'master' into f-aws-glue
drewsonne Jan 10, 2018
7d6e0dd
Merge branch 'master' into f-aws-glue
drewsonne Jan 10, 2018
853efbd
Use American spelling
drewsonne Jan 10, 2018
f285890
Remove un-used Computed attributes for schema vars
Jan 11, 2018
46302bf
Merge branch 'master' into f-aws-glue
Jan 11, 2018
15c87e0
Merge branch 'master' into f-aws-glue
Jan 11, 2018
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 aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/aws/aws-sdk-go/service/emr"
"github.com/aws/aws-sdk-go/service/firehose"
"github.com/aws/aws-sdk-go/service/glacier"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/inspector"
"github.com/aws/aws-sdk-go/service/iot"
Expand Down Expand Up @@ -182,6 +183,7 @@ type AWSClient struct {
wafregionalconn *wafregional.WAFRegional
iotconn *iot.IoT
batchconn *batch.Batch
glueconn *glue.Glue
athenaconn *athena.Athena
dxconn *directconnect.DirectConnect
}
Expand Down Expand Up @@ -394,6 +396,7 @@ func (c *Config) Client() (interface{}, error) {
client.wafconn = waf.New(sess)
client.wafregionalconn = wafregional.New(sess)
client.batchconn = batch.New(sess)
client.glueconn = glue.New(sess)
client.athenaconn = athena.New(sess)
client.dxconn = directconnect.New(sess)

Expand Down
30 changes: 30 additions & 0 deletions aws/import_aws_glue_catalog_database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package aws

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAWSGlueCatalogDatabaseVault_importBasic(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Dang, sorry I didn't notice this copypasta earlier - just needs Vault removed

resourceName := "aws_glue_catalog_database.test"
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGlueDatabaseDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccGlueCatalogDatabase_basic(rInt),
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func Provider() terraform.ResourceProvider {
"aws_emr_security_configuration": resourceAwsEMRSecurityConfiguration(),
"aws_flow_log": resourceAwsFlowLog(),
"aws_glacier_vault": resourceAwsGlacierVault(),
"aws_glue_catalog_database": resourceAwsGlueCatalogDatabase(),
"aws_iam_access_key": resourceAwsIamAccessKey(),
"aws_iam_account_alias": resourceAwsIamAccountAlias(),
"aws_iam_account_password_policy": resourceAwsIamAccountPasswordPolicy(),
Expand Down
149 changes: 149 additions & 0 deletions aws/resource_aws_glue_catalog_database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package aws

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/hashicorp/terraform/helper/schema"
"log"
)

func resourceAwsGlueCatalogDatabase() *schema.Resource {
return &schema.Resource{
Create: resourceAwsGlueCatalogDatabaseCreate,
Read: resourceAwsGlueCatalogDatabaseRead,
Update: resourceAwsGlueCatalogDatabaseUpdate,
Delete: resourceAwsGlueCatalogDatabaseDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"description": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(likely copypasta) since Go 1.7 you do not need to duplicate the &schema.Schema for each of the attributes

Type: schema.TypeString,
Optional: true,
},
"location_uri": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Required: true,
},
"parameters": &schema.Schema{
Type: schema.TypeMap,
Elem: schema.TypeString,
Optional: true,
},
"create_time": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most or all AWS resources we do not export create/update time attributes like these. Is there a specific use case for dealing with this attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no specific use case, my motivation was simply to expose the Glue API for the Database object with as little logic as possible. If the convention within the AWS resources in terraform is not to expose this, I will remove it. Can you just confirm that hiding the CreateTime attribute would be part of the convention within the provider?

Type: schema.TypeString,
Computed: true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for setting the above 3 fields as Computed? I tried removing the flag and all acceptance tests passed which makes me think there is no reason, but maybe I'm wrong and the behaviour just isn't covered in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radeksimko the motivation is because of the above discussion re computed flags with @bflad

bflad:

In general, we want to know if something occurred outside Terraform as well (e.g. a manual update in the UI). I believe the intent of Computed: true for the other optional attributes is to catch these scenarios. If you look around at other resource schemas, you should see that the two are often paired together.

I don't know the functional requirements here, and testing the functionality describe i the quote here to import would require a step in between each resource.TestStep which goes into AWS and modifies the AWS resource.

I'm happy to do this, but I have not seen any prior art as to how one would go about this. But also, I would like to have some sort of idea about what is expected in terms of functionality so I don't end up bouncing back and forth between two different opinions of Reviewers :-)

I'm not sure who is closer to the project between yourself @radeksimko and @bflad :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will ask @bflad about this when he wakes up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed with @bflad privately that this was just a misunderstanding and we mutually agreed it should be removed from the schema here.

Sorry for any confusion caused by this!

After that I believe we're ready to merge it 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, aside from obvious things (like instance ids i-12345678, etc), when should the Computed: tag be used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computed w/ Optional is typically used when the API automatically sets unpredictable default value or when the value is generally not static and depends on other attributes.

It is an expectation of Terraform users to see difference in plan if something has changed outside of Terraform (e.g. someone manually changed description through AWS Console or AWS CLI). User has some options to ignore certain changes if they wish (via lifecycle block), but overall this is a desired behaviour.

The downside of marking something Computed is that it will ignore such changes, but sometimes it's necessary. We always prefer static Default where possible.

Computed only is used for any IDs or anything not defined in the config and returned by the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there is a case above #2175 (comment) where I have a value (catalog_id), which at the moment is only able to be set as an AWS AccountID (not necessarily the same AccountID as TF is running as). If the catalog_id is omitted, AWS will fill it in.

I assume this is because AWS will eventually have the ability for multiple catalogues in a single account, a globally unique namespace for public catalogues, or something such. This then is a case where the user could provide catalog_id, but if they don't AWS will compute it.

This variable is currently Computed: true and given what you said above it seems like it is an ID, but... it could be a user set value, so it feels like a grey area, but... if it changes, the resource needs to be re-built, so it should never turn up as a diff in an update operation.

But, I would be correct in saying that this catalog_id is a valid use case for Computed: true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, catalog_id is a valid use case. It's kind of a special case I didn't mention in my previous explanation.

},
}
}

func resourceAwsGlueCatalogDatabaseCreate(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn
name := d.Get("name").(string)

input := &glue.CreateDatabaseInput{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this form, it does not support this input parameter:

    // The ID of the Data Catalog in which to create the database. If none is supplied,
    // the AWS account ID is used by default.
    CatalogId *string `min:"1" type:"string"`

I am wondering if we need to or should support this.

DatabaseInput: &glue.DatabaseInput{
Name: aws.String(name),
},
}

_, err := glueconn.CreateDatabase(input)
if err != nil {
return fmt.Errorf("Error creating Catalogue Database: %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: the service name is spelled catalog (American spelling).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah noo! I'm an Australian living in London! I think the world would be a bit better off with a generous sprinkling of vowels here and there ;-P

}

d.SetId(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the above about potentially supporting separate catalogs in an AWS account, does this resource ID need to support the CatalogId as well? e.g. fmt.Sprintf("%s:%s", meta.(*AWSClient).accountid, name)


return resourceAwsGlueCatalogDatabaseUpdate(d, meta)
}

func resourceAwsGlueCatalogDatabaseUpdate(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn
doUpdate := false
input := &glue.UpdateDatabaseInput{
DatabaseInput: &glue.DatabaseInput{
Name: aws.String(d.Id()),
},
Name: aws.String(d.Id()),
}

if ok := d.HasChange("description"); ok {
doUpdate = true
input.DatabaseInput.Description = aws.String(
d.Get("description").(string),
)
}

if ok := d.HasChange("location_uri"); ok {
doUpdate = true
input.DatabaseInput.LocationUri = aws.String(
d.Get("location_uri").(string),
)
}

if ok := d.HasChange("parameters"); ok {
doUpdate = true
input.DatabaseInput.Parameters = make(map[string]*string)
for key, value := range d.Get("parameters").(map[string]interface{}) {
input.DatabaseInput.Parameters[key] = aws.String(value.(string))
}
}

if doUpdate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but this is a tiny little bit more difficult to read/understand - could be simplified to if d.HasChange("description") || d.HasChange("location_uri") || d.HasChange("parameters") {.

if _, err := glueconn.UpdateDatabase(input); err != nil {
return err
}
}

return resourceAwsGlueCatalogDatabaseRead(d, meta)
}

func resourceAwsGlueCatalogDatabaseRead(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn

input := &glue.GetDatabaseInput{
Name: aws.String(d.Id()),
}

out, err := glueconn.GetDatabase(input)
if err != nil {
return fmt.Errorf("Error reading Glue Cataloge Database: %s", err.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: typo 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do you mind adding a check for database which was removed outside of Terraform? something like this should suffice:

if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") {
	log.Printf("[WARN] Glue Catalog Database (%s) not found, removing from state", d.Id())
	d.SetId("")
}

you may also add an acceptance test verifying this behaviour, similar to e.g. https://github.com/terraform-providers/terraform-provider-aws/blob/79ed212c594fd8e848d0274cd0efc70bbf4cede8/aws/resource_aws_eip_test.go#L220-L238

but the test is not a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned above, I wish to round out the whole AWS Glue product set for terraform. For the sake of my sanity (getting a PR merged), can I put this test in a subsequent PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a test in a subsequent PR is totally fine. 😉

}

d.Set("name", d.Id())
d.Set("create_time", out.Database.CreateTime)
d.Set("description", out.Database.Description)
d.Set("location_uri", out.Database.LocationUri)

dParams := make(map[string]string)
if len(out.Database.Parameters) > 0 {
for key, value := range out.Database.Parameters {
dParams[key] = *value
}
}
d.Set("parameters", dParams)

return nil
}

func resourceAwsGlueCatalogDatabaseDelete(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn

log.Printf("[DEBUG] Glue Catalog Database: %s", d.Id())
_, err := glueconn.DeleteDatabase(&glue.DeleteDatabaseInput{
Name: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error deleting Glue Catalog Database: %s", err.Error())
}
return nil
}
128 changes: 128 additions & 0 deletions aws/resource_aws_glue_catalog_database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package aws

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/glue"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSGlueCatalogDatabase_basic(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a second resource.TestStep that updates the attributes and ensures the updates propagate properly to AWS/Terraform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have attempted to do this, but I struggling to get it working.
When I add a second step with a modified description field, I get:

testing.go:503: Step 0 error: After applying this step, the plan was not empty:
	
	DIFF:
	
	DESTROY/CREATE: aws_glue_catalog_database.test
	  catalog_id:        "440474553311" => "" (forces new resource)
	  description:       "A test catalog from terraform" => "A test catalog from terraform"
	  location_uri:      "my-location" => "my-location"
	  name:              "my_test_catalog_database_6335041086110733121" => "my_test_catalog_database_6335041086110733121"
	  parameters.%:      "3" => "3"
	  parameters.param1: "value1" => "value1"
	  parameters.param2: "1" => "1"
	  parameters.param3: "50" => "50"
	
	STATE:
	
	aws_glue_catalog_database.test:
	  ID = 440474553311:my_test_catalog_database_6335041086110733121
	  catalog_id = 440474553311
	  description = A test catalog from terraform
	  location_uri = my-location
	  name = my_test_catalog_database_6335041086110733121
	  parameters.% = 3
	  parameters.param1 = value1
	  parameters.param2 = 1
	  parameters.param3 = 50

When I take the second step out, it works, so I am not sure why it's saying the plan was not empty at the end if it succeeded with the first step. If there's only one step, does it not test for an empty plan?

I've had a look at https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_ecs_service_test.go to get an idea of a config change test, but I can't see why mine fails and that one works. @bflad , are you able to shed any light on this? I'm keen to get this test working, as it's a problem I ran across in my own provider. That is, how to test diffs successfully.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding Computed: true to the optional catalog_id attribute in the schema. This should tell Terraform that its value is allowed to be set from the provider instead of just the configuration. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr Computed: true should be set on any attributes that AWS might return to be set in the state that aren't required by writing Terraform configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks! I was under the impression Computed: true was only for attributes which are computed, and not attributes which could be computed. This is working on my integration tests now.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSGlueCatalogDatabase_*'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSGlueCatalogDatabase_* -timeout 120m
=== RUN   TestAccAWSGlueCatalogDatabaseVault_importBasic
--- PASS: TestAccAWSGlueCatalogDatabaseVault_importBasic (22.05s)
=== RUN   TestAccAWSGlueCatalogDatabase_basic
--- PASS: TestAccAWSGlueCatalogDatabase_basic (33.43s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	55.511s

rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGlueDatabaseDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccGlueCatalogDatabase_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckGlueCatalogDatabaseExists("aws_glue_catalog_database.test"),
resource.TestCheckResourceAttr(
"aws_glue_catalog_database.test",
"description",
"A test catalog from terraform",
),
resource.TestCheckResourceAttr(
"aws_glue_catalog_database.test",
"location_uri",
"my-location",
),
resource.TestCheckResourceAttr(
"aws_glue_catalog_database.test",
"parameters.param1",
"value1",
),
resource.TestCheckResourceAttr(
"aws_glue_catalog_database.test",
"parameters.param2",
"1",
),
resource.TestCheckResourceAttr(
"aws_glue_catalog_database.test",
"parameters.param3",
"50",
),
),
},
},
})
}

func testAccCheckGlueDatabaseDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).glueconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_glue_catalog_database" {
continue
}

input := &glue.GetDatabaseInput{
Name: aws.String(rs.Primary.ID),
}
if _, err := conn.GetDatabase(input); err != nil {
//Verify the error is what we want
if ae, ok := err.(awserr.Error); ok && ae.Code() == "EntityNotFoundException" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes about this:

  • We have a helper function which can let you remove the awserr import from this file
  • I would recommend using the SDK constant here

isAWSErr(err, glue.ErrCodeEntityNotFoundException, "")

continue
}

return err
}
return fmt.Errorf("still exists")
}
return nil
}

func testAccGlueCatalogDatabase_basic(rInt int) string {
return fmt.Sprintf(`
resource "aws_glue_catalog_database" "test" {
name = "my_test_catalog_database_%d"
description = "A test catalog from terraform"
location_uri = "my-location"
parameters {
param1 = "value1"
param2 = true
param3 = 50
}
}
`, rInt)
}

func testAccCheckGlueCatalogDatabaseExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}

glueconn := testAccProvider.Meta().(*AWSClient).glueconn
out, err := glueconn.GetDatabase(&glue.GetDatabaseInput{
Name: aws.String(rs.Primary.ID),
})

if err != nil {
return err
}

if out.Database == nil {
return fmt.Errorf("No Glue Database Found")
}

if *out.Database.Name != rs.Primary.ID {
return fmt.Errorf("Glue Database Mismatch - existing: %q, state: %q",
*out.Database, rs.Primary.ID)
}

return nil
}
}
8 changes: 8 additions & 0 deletions website/aws.erb
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,14 @@
</ul>
</li>

<li<%= sidebar_current("docs-aws-resource-glue") %>>
<a href="#">Glue Resources</a>
<ul class="nav nav-visible">
<li<%= sidebar_current("docs-aws-resource-glue-catalog-database") %>>
<a href="/docs/providers/aws/r/glue_catalog_database.html">aws_glue_catalog_database</a>
</li>
</ul>
</li>

<li<%= sidebar_current("docs-aws-resource-iam") %>>
<a href="#">IAM Resources</a>
Expand Down
42 changes: 42 additions & 0 deletions website/docs/r/glue_catalog_database.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
layout: "aws"
page_title: "AWS: aws_glue_catalog_database"
sidebar_current: "docs-aws-resource-glue-catalog-database"
description: |-
Provides a Glue Catalog Database.
---

# aws\_glue\_catalog\_database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: (likely copypasta) antislashes in the documentation are no longer needed


Provides a Glue Catalog Database Resource. You can refer to the [Glue Developer Guide](http://docs.aws.amazon.com/glue/latest/dg/populate-data-catalog.html) for a full explanation of the Glue Data Catalog functionality

## Example Usage

```hcl-terraform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We tend to use just hcl here for simplicity.

resource "aws_glue_catalog_database" "aws_glue_catalog_database" {
name = "MyCatalogDatabase"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the database.
* `description` - (Optional) Description of the database.
* `location_uri` - (Optional) The location of the database (for example, an HDFS path).
* `parameters` - (Optional) A list of key-value pairs that define parameters and properties of the database.

## Attributes Reference

The following attributes are exported:
Copy link
Contributor

@bflad bflad Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nitpicks:

  • (likely copypasta) this should read The following additional attributes are exported
  • We should list what the id attribute is here


* `create_time` - The time at which the metadata database was created in the catalog.

## Import

Glue Catalog Databasess can be imported using the `name`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Databases


```
$ terraform import aws_glue_catalog_database.database my_database
```