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 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..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) @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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"), @@ -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), @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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"}, }, }, }) @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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 } @@ -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 @@ -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) } @@ -739,6 +778,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -766,6 +809,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -787,6 +834,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -808,6 +859,10 @@ resource "aws_sagemaker_domain" "test" { } } } + + retention_policy { + home_efs_file_system = "Delete" + } } `, rName) } @@ -852,6 +907,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: