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

Lake Formation Resource #13267

Merged
merged 23 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
abddf85
New resource: aws_lakeformation_datalake_settings
gmazelier May 9, 2020
9d54d24
Check resource state on destroy
gmazelier May 9, 2020
e7f3f7d
Add documentation
gmazelier May 9, 2020
c4e9992
Add AWS region in settings identifier
gmazelier May 10, 2020
5b52ecf
Add missing website LakeFormation subcategory
gmazelier May 10, 2020
e62033e
Rename expand and flatten functions for admins list
gmazelier May 11, 2020
efbe990
Make data lake admins list a set
gmazelier May 11, 2020
6673cd5
Use Lake Formation official spelling
gmazelier May 11, 2020
92cb24a
Cleanup
gmazelier May 11, 2020
5ed60ca
New resource: aws_lakeformation_resource
gmazelier May 10, 2020
acc1152
Add resource documentation
gmazelier May 10, 2020
6ba35a3
Cleanup
gmazelier May 11, 2020
75d25e8
Better validations
gmazelier May 12, 2020
35d8d96
Rework Lake Formation to design
YakDriver Dec 8, 2020
09123f6
tests/resource/lakeformation_resource: Add exists and disappears
YakDriver Dec 9, 2020
8f7614b
resource/lakeformation: Remove lakeformation_datalake_settings
YakDriver Dec 9, 2020
896f026
docs/lakeformation_resource: Fix formatting
YakDriver Dec 9, 2020
8555491
docs/lakeformation_datalake_settings: Remove from branch (part of lat…
YakDriver Dec 9, 2020
7455563
tests/lakeformation_resource: Fix to use ARN check func
YakDriver Dec 9, 2020
c30f5fb
resource/lakeformation_resource: Remove go.mod, go.sum
YakDriver Dec 9, 2020
70b9151
tests/lakeformation_resource: Add precheck
YakDriver Dec 9, 2020
7e920ba
resource/lakeformation_resource: Improve error messages
YakDriver Dec 9, 2020
870c35d
resource/lakeformation_resource: Use ForceNew for more update options
YakDriver Dec 9, 2020
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
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ func Provider() *schema.Provider {
"aws_kms_grant": resourceAwsKmsGrant(),
"aws_kms_key": resourceAwsKmsKey(),
"aws_kms_ciphertext": resourceAwsKmsCiphertext(),
"aws_lakeformation_resource": resourceAwsLakeFormationResource(),
"aws_lambda_alias": resourceAwsLambdaAlias(),
"aws_lambda_code_signing_config": resourceAwsLambdaCodeSigningConfig(),
"aws_lambda_event_source_mapping": resourceAwsLambdaEventSourceMapping(),
Expand Down
119 changes: 119 additions & 0 deletions aws/resource_aws_lakeformation_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package aws

import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lakeformation"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAwsLakeFormationResource() *schema.Resource {
return &schema.Resource{
Create: resourceAwsLakeFormationResourceCreate,
Read: resourceAwsLakeFormationResourceRead,
Delete: resourceAwsLakeFormationResourceDelete,

Schema: map[string]*schema.Schema{
"last_modified": {
Type: schema.TypeString,
Computed: true,
},
"resource_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateArn,
},
"role_arn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateArn,
},
},
}
}

func resourceAwsLakeFormationResourceCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn
resourceArn := d.Get("resource_arn").(string)

input := &lakeformation.RegisterResourceInput{
ResourceArn: aws.String(resourceArn),
}

if v, ok := d.GetOk("role_arn"); ok {
input.RoleArn = aws.String(v.(string))
} else {
input.UseServiceLinkedRole = aws.Bool(true)
}

_, err := conn.RegisterResource(input)

if tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeAlreadyExistsException) {
log.Printf("[WARN] Lake Formation Resource (%s) already exists", resourceArn)
} else if err != nil {
return fmt.Errorf("error registering Lake Formation Resource (%s): %s", resourceArn, err)
}

d.SetId(resourceArn)
return resourceAwsLakeFormationResourceRead(d, meta)
}

func resourceAwsLakeFormationResourceRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn
resourceArn := d.Get("resource_arn").(string)

input := &lakeformation.DescribeResourceInput{
ResourceArn: aws.String(resourceArn),
}

output, err := conn.DescribeResource(input)

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) {
log.Printf("[WARN] Lake Formation Resource (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

if err != nil {
return fmt.Errorf("error getting Lake Formation Resource (%s): %w", d.Id(), err)
}

if output == nil || output.ResourceInfo == nil {
return fmt.Errorf("error getting Lake Formation Resource (%s): empty response", d.Id())
}

if err != nil {
return fmt.Errorf("error reading Lake Formation Resource (%s): %w", d.Id(), err)
}

// d.Set("resource_arn", output.ResourceInfo.ResourceArn) // output not including resource arn currently
d.Set("role_arn", output.ResourceInfo.RoleArn)
if output.ResourceInfo.LastModified != nil { // output not including last modified currently
d.Set("last_modified", output.ResourceInfo.LastModified.Format(time.RFC3339))
}

return nil
}

func resourceAwsLakeFormationResourceDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lakeformationconn
resourceArn := d.Get("resource_arn").(string)

input := &lakeformation.DeregisterResourceInput{
ResourceArn: aws.String(resourceArn),
}

_, err := conn.DeregisterResource(input)
if err != nil {
return fmt.Errorf("error deregistering Lake Formation Resource (%s): %w", d.Id(), err)
}

return nil
}
Loading