-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13250 from gmazelier/lakeformation_datalake_settings
Lake Formation Data Lake Settings
- Loading branch information
Showing
10 changed files
with
750 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
aws/data_source_aws_lakeformation_data_lake_settings.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"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" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/hashcode" | ||
) | ||
|
||
func dataSourceAwsLakeFormationDataLakeSettings() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsLakeFormationDataLakeSettingsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"catalog_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"create_database_default_permissions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"permissions": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"principal": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"create_table_default_permissions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"permissions": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"principal": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"data_lake_admins": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"trusted_resource_owners": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsLakeFormationDataLakeSettingsRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).lakeformationconn | ||
|
||
input := &lakeformation.GetDataLakeSettingsInput{} | ||
|
||
if v, ok := d.GetOk("catalog_id"); ok { | ||
input.CatalogId = aws.String(v.(string)) | ||
} | ||
d.SetId(fmt.Sprintf("%d", hashcode.String(input.String()))) | ||
|
||
output, err := conn.GetDataLakeSettings(input) | ||
|
||
if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, lakeformation.ErrCodeEntityNotFoundException) { | ||
log.Printf("[WARN] Lake Formation data lake settings (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error reading Lake Formation data lake settings (%s): %w", d.Id(), err) | ||
} | ||
|
||
if output == nil || output.DataLakeSettings == nil { | ||
return fmt.Errorf("error reading Lake Formation data lake settings (%s): empty response", d.Id()) | ||
} | ||
|
||
settings := output.DataLakeSettings | ||
|
||
d.Set("create_database_default_permissions", flattenDataLakeSettingsCreateDefaultPermissions(settings.CreateDatabaseDefaultPermissions)) | ||
d.Set("create_table_default_permissions", flattenDataLakeSettingsCreateDefaultPermissions(settings.CreateTableDefaultPermissions)) | ||
d.Set("data_lake_admins", flattenDataLakeSettingsAdmins(settings.DataLakeAdmins)) | ||
d.Set("trusted_resource_owners", flattenStringList(settings.TrustedResourceOwners)) | ||
|
||
return nil | ||
} |
56 changes: 56 additions & 0 deletions
56
aws/data_source_aws_lakeformation_data_lake_settings_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/lakeformation" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAWSLakeFormationDataLakeSettingsDataSource_serial(t *testing.T) { | ||
testCases := map[string]func(t *testing.T){ | ||
"basic": testAccAWSLakeFormationDataLakeSettingsDataSource_basic, | ||
// if more tests are added, they should be serial (data catalog is account-shared resource) | ||
} | ||
|
||
for name, tc := range testCases { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
} | ||
|
||
func testAccAWSLakeFormationDataLakeSettingsDataSource_basic(t *testing.T) { | ||
callerIdentityName := "data.aws_caller_identity.current" | ||
resourceName := "data.aws_lakeformation_data_lake_settings.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSLakeFormationDataLakeSettingsDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSLakeFormationDataLakeSettingsDataSourceConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(resourceName, "catalog_id", callerIdentityName, "account_id"), | ||
resource.TestCheckResourceAttr(resourceName, "data_lake_admins.#", "1"), | ||
resource.TestCheckResourceAttrPair(resourceName, "data_lake_admins.0", callerIdentityName, "arn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccAWSLakeFormationDataLakeSettingsDataSourceConfig_basic = ` | ||
data "aws_caller_identity" "current" {} | ||
resource "aws_lakeformation_data_lake_settings" "test" { | ||
catalog_id = data.aws_caller_identity.current.account_id | ||
data_lake_admins = [data.aws_caller_identity.current.arn] | ||
} | ||
data "aws_lakeformation_data_lake_settings" "test" { | ||
catalog_id = aws_lakeformation_data_lake_settings.test.catalog_id | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.