Skip to content

Commit

Permalink
Merge pull request hashicorp#18562 from DrFaust92/r/sagemaker_domain_…
Browse files Browse the repository at this point in the history
…retain_efs

r/sagemaker_domain - retention policy for efs file system
  • Loading branch information
ewbankkit authored Jul 15, 2021
2 parents 17763e0 + 062fee7 commit a3ede2b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .changelog/18562.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_sagemaker_domain: Add support for `retention_policy`
```
4 changes: 4 additions & 0 deletions aws/resource_aws_sagemaker_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ resource "aws_sagemaker_domain" "test" {
default_user_settings {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
}
resource "aws_sagemaker_user_profile" "test" {
Expand Down
38 changes: 35 additions & 3 deletions aws/resource_aws_sagemaker_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ func resourceAwsSagemakerDomain() *schema.Resource {
},
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
"retention_policy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"home_efs_file_system": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(sagemaker.RetentionType_Values(), false),
Default: sagemaker.RetentionTypeRetain,
},
},
},
},
"url": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -377,9 +393,10 @@ func resourceAwsSagemakerDomainDelete(d *schema.ResourceData, meta interface{})

input := &sagemaker.DeleteDomainInput{
DomainId: aws.String(d.Id()),
RetentionPolicy: &sagemaker.RetentionPolicy{
HomeEfsFileSystem: aws.String(sagemaker.RetentionTypeDelete),
},
}

if v, ok := d.GetOk("retention_policy"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.RetentionPolicy = expandSagemakerRetentionPolicy(v.([]interface{}))
}

if _, err := conn.DeleteDomain(input); err != nil {
Expand All @@ -396,6 +413,21 @@ func resourceAwsSagemakerDomainDelete(d *schema.ResourceData, meta interface{})

return nil
}
func expandSagemakerRetentionPolicy(l []interface{}) *sagemaker.RetentionPolicy {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

config := &sagemaker.RetentionPolicy{}

if v, ok := m["home_efs_file_system"].(string); ok && v != "" {
config.HomeEfsFileSystem = aws.String(v)
}

return config
}

func expandSagemakerDomainDefaultUserSettings(l []interface{}) *sagemaker.UserSettings {
if len(l) == 0 || l[0] == nil {
Expand Down
119 changes: 89 additions & 30 deletions aws/resource_aws_sagemaker_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func testSweepSagemakerDomains(region string) error {
r := resourceAwsSagemakerDomain()
d := r.Data(nil)
d.SetId(aws.StringValue(domain.DomainId))
d.Set("retention_policy.0.home_efs_file_system", "Delete")
err = r.Delete(d, client)
if err != nil {
log.Printf("[ERROR] %s", err)
Expand Down Expand Up @@ -142,9 +143,10 @@ func testAccAWSSagemakerDomain_basic(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand All @@ -169,9 +171,10 @@ func testAccAWSSagemakerDomain_kms(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand All @@ -197,9 +200,10 @@ func testAccAWSSagemakerDomain_tags(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
{
Config: testAccAWSSagemakerDomainConfigTags2(rName, "key1", "value1updated", "key2", "value2"),
Expand Down Expand Up @@ -242,9 +246,10 @@ func testAccAWSSagemakerDomain_securityGroup(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
{
Config: testAccAWSSagemakerDomainConfigSecurityGroup2(rName),
Expand Down Expand Up @@ -281,9 +286,10 @@ func testAccAWSSagemakerDomain_sharingSettings(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -311,9 +317,10 @@ func testAccAWSSagemakerDomain_tensorboardAppSettings(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -342,9 +349,10 @@ func testAccAWSSagemakerDomain_tensorboardAppSettingsWithImage(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -372,9 +380,10 @@ func testAccAWSSagemakerDomain_kernelGatewayAppSettings(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -410,9 +419,10 @@ func testAccAWSSagemakerDomain_kernelGatewayAppSettings_customImage(t *testing.T
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -440,9 +450,10 @@ func testAccAWSSagemakerDomain_jupyterServerAppSettings(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
Expand Down Expand Up @@ -582,6 +593,10 @@ resource "aws_sagemaker_domain" "test" {
default_user_settings {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -603,6 +618,10 @@ resource "aws_sagemaker_domain" "test" {
default_user_settings {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -623,6 +642,10 @@ resource "aws_sagemaker_domain" "test" {
execution_role = aws_iam_role.test.arn
security_groups = [aws_security_group.test.id]
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -647,6 +670,10 @@ resource "aws_sagemaker_domain" "test" {
execution_role = aws_iam_role.test.arn
security_groups = [aws_security_group.test.id, aws_security_group.test2.id]
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -663,6 +690,10 @@ resource "aws_sagemaker_domain" "test" {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
tags = {
%[2]q = %[3]q
}
Expand All @@ -682,6 +713,10 @@ resource "aws_sagemaker_domain" "test" {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
tags = {
%[2]q = %[3]q
%[4]q = %[5]q
Expand Down Expand Up @@ -718,6 +753,10 @@ resource "aws_sagemaker_domain" "test" {
s3_output_path = "s3://${aws_s3_bucket.test.bucket}/sharing"
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -739,6 +778,10 @@ resource "aws_sagemaker_domain" "test" {
}
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand Down Expand Up @@ -766,6 +809,10 @@ resource "aws_sagemaker_domain" "test" {
}
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -787,6 +834,10 @@ resource "aws_sagemaker_domain" "test" {
}
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand All @@ -808,6 +859,10 @@ resource "aws_sagemaker_domain" "test" {
}
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand Down Expand Up @@ -852,6 +907,10 @@ resource "aws_sagemaker_domain" "test" {
}
}
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName, baseImage)
}
4 changes: 4 additions & 0 deletions aws/resource_aws_sagemaker_user_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ resource "aws_sagemaker_domain" "test" {
default_user_settings {
execution_role = aws_iam_role.test.arn
}
retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName)
}
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/sagemaker_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The following arguments are supported:
* `vpc_id` - (Required) The ID of the Amazon Virtual Private Cloud (VPC) that Studio uses for communication.
* `subnet_ids` - (Required) The VPC subnets that Studio uses for communication.
* `default_user_settings` - (Required) The default user settings. See [Default User Settings](#default-user-settings) below.
* `retention_policy` - (Optional) The retention policy for this domain, which specifies whether resources will be retained after the Domain is deleted. By default, all resources are retained. See [Retention Policy](#retention-policy) below.
* `kms_key_id` - (Optional) The AWS KMS customer managed CMK used to encrypt the EFS volume attached to the domain.
* `app_network_access_type` - (Optional) Specifies the VPC used for non-EFS traffic. The default value is `PublicInternetOnly`. Valid values are `PublicInternetOnly` and `VpcOnly`.
* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
Expand Down Expand Up @@ -138,6 +139,10 @@ The following arguments are supported:
* `image_name` - (Required) The name of the Custom Image.
* `image_version_number` - (Optional) The version number of the Custom Image.

### Retention Policy

* `home_efs_file_system` - (Optional) The retention policy for data stored on an Amazon Elastic File System (EFS) volume. Default value is `Retain`.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down

0 comments on commit a3ede2b

Please sign in to comment.