From d9aab916290f3f28763f8ef0465f8e3e8eb57dd5 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sun, 4 Apr 2021 12:43:17 +0300 Subject: [PATCH 1/4] retention policy for efs file system --- aws/resource_aws_sagemaker_app_test.go | 4 + aws/resource_aws_sagemaker_domain.go | 38 +++++- aws/resource_aws_sagemaker_domain_test.go | 118 +++++++++++++----- ...esource_aws_sagemaker_user_profile_test.go | 4 + website/docs/r/sagemaker_domain.html.markdown | 5 + 5 files changed, 136 insertions(+), 33 deletions(-) diff --git a/aws/resource_aws_sagemaker_app_test.go b/aws/resource_aws_sagemaker_app_test.go index 5870e50db72..0cf5787350e 100644 --- a/aws/resource_aws_sagemaker_app_test.go +++ b/aws/resource_aws_sagemaker_app_test.go @@ -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" { diff --git a/aws/resource_aws_sagemaker_domain.go b/aws/resource_aws_sagemaker_domain.go index 4ca348eb607..175d35b15bb 100644 --- a/aws/resource_aws_sagemaker_domain.go +++ b/aws/resource_aws_sagemaker_domain.go @@ -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, @@ -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 { @@ -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 { diff --git a/aws/resource_aws_sagemaker_domain_test.go b/aws/resource_aws_sagemaker_domain_test.go index 793e7949726..fa54d8718ec 100644 --- a/aws/resource_aws_sagemaker_domain_test.go +++ b/aws/resource_aws_sagemaker_domain_test.go @@ -142,9 +142,10 @@ func testAccAWSSagemakerDomain_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -169,9 +170,10 @@ func testAccAWSSagemakerDomain_kms(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -197,9 +199,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"), @@ -242,9 +245,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), @@ -281,9 +285,10 @@ func testAccAWSSagemakerDomain_sharingSettings(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -311,9 +316,10 @@ func testAccAWSSagemakerDomain_tensorboardAppSettings(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -342,9 +348,10 @@ func testAccAWSSagemakerDomain_tensorboardAppSettingsWithImage(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -372,9 +379,10 @@ func testAccAWSSagemakerDomain_kernelGatewayAppSettings(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -410,9 +418,10 @@ func testAccAWSSagemakerDomain_kernelGatewayAppSettings_customImage(t *testing.T ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -440,9 +449,10 @@ func testAccAWSSagemakerDomain_jupyterServerAppSettings(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, }, }, }) @@ -582,6 +592,10 @@ resource "aws_sagemaker_domain" "test" { default_user_settings { execution_role = aws_iam_role.test.arn } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -603,6 +617,10 @@ resource "aws_sagemaker_domain" "test" { default_user_settings { execution_role = aws_iam_role.test.arn } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -623,6 +641,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) } @@ -647,6 +669,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) } @@ -663,6 +689,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 } @@ -682,6 +712,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 @@ -718,6 +752,10 @@ resource "aws_sagemaker_domain" "test" { s3_output_path = "s3://${aws_s3_bucket.test.bucket}/sharing" } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -739,6 +777,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -766,6 +808,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -787,6 +833,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -808,6 +858,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -852,6 +906,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName, baseImage) } diff --git a/aws/resource_aws_sagemaker_user_profile_test.go b/aws/resource_aws_sagemaker_user_profile_test.go index 1aa633c7923..eb5b2f10d1a 100644 --- a/aws/resource_aws_sagemaker_user_profile_test.go +++ b/aws/resource_aws_sagemaker_user_profile_test.go @@ -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) } diff --git a/website/docs/r/sagemaker_domain.html.markdown b/website/docs/r/sagemaker_domain.html.markdown index 2bd8a25252d..af437b6ce21 100644 --- a/website/docs/r/sagemaker_domain.html.markdown +++ b/website/docs/r/sagemaker_domain.html.markdown @@ -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. @@ -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: From dac2336620914bb219726cd8d965398709e88bb0 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sun, 4 Apr 2021 12:54:17 +0300 Subject: [PATCH 2/4] changelog --- .changelog/18562.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/18562.txt diff --git a/.changelog/18562.txt b/.changelog/18562.txt new file mode 100644 index 00000000000..7d25f37b7a3 --- /dev/null +++ b/.changelog/18562.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_sagemaker_domain: Add support for `retention_policy` +``` \ No newline at end of file From 1c21d36013e7076339f3873fd1fee6a578820e13 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sun, 4 Apr 2021 13:02:09 +0300 Subject: [PATCH 3/4] lint --- aws/resource_aws_sagemaker_domain_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_sagemaker_domain_test.go b/aws/resource_aws_sagemaker_domain_test.go index fa54d8718ec..feb635451eb 100644 --- a/aws/resource_aws_sagemaker_domain_test.go +++ b/aws/resource_aws_sagemaker_domain_test.go @@ -620,7 +620,7 @@ resource "aws_sagemaker_domain" "test" { retention_policy { home_efs_file_system = "Delete" - } + } } `, rName) } @@ -644,7 +644,7 @@ resource "aws_sagemaker_domain" "test" { retention_policy { home_efs_file_system = "Delete" - } + } } `, rName) } @@ -672,7 +672,7 @@ resource "aws_sagemaker_domain" "test" { retention_policy { home_efs_file_system = "Delete" - } + } } `, rName) } From 062fee7032b9484c699f459b03a8f88d7e26184b Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Mon, 28 Jun 2021 19:59:57 +0300 Subject: [PATCH 4/4] ammend sweeper --- aws/resource_aws_sagemaker_domain_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_sagemaker_domain_test.go b/aws/resource_aws_sagemaker_domain_test.go index feb635451eb..b11720bff58 100644 --- a/aws/resource_aws_sagemaker_domain_test.go +++ b/aws/resource_aws_sagemaker_domain_test.go @@ -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)