hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.73k stars 9.09k forks source link

[Bug]: r_studio_package_manager_url missing in SageMaker domain API calls #38546

Closed felipempda closed 1 month ago

felipempda commented 1 month ago

Terraform Core Version

1.9.3

AWS Provider Version

5.6.0

Affected Resource(s)

aws_sagemaker_domain

Expected Behavior

r_studio_package_manager_url should be used during SageMaker domain creation/update when set

For example, the following code shows it in the plan:

resource "aws_sagemaker_domain" "rstudio" {
  domain_name = "test"
  auth_mode   = "IAM"
  vpc_id      = "vpc-vpc-xxxxxxxxxxxx"
  subnet_ids  = ["subnet-yyyyyyyyyyy"]

  domain_settings {

    r_studio_server_pro_domain_settings {
      r_studio_connect_url         = "https://connect.domain.com"
      r_studio_package_manager_url = "https://package.domain.com"
      domain_execution_role_arn    = "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole"
      default_resource_spec {
        instance_type                 = "system" 
        sagemaker_image_arn           = "arn:aws:sagemaker:ca-central-1:310906938811:image/rstudio-workbench-2023.03"
       }
    }
  }

  default_user_settings {
    execution_role = "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole"

  }

  retention_policy {
    home_efs_file_system = "Delete"
  }
}

And here it's the log after applying it:

# aws_sagemaker_domain.rstudio will be created
  + resource "aws_sagemaker_domain" "rstudio" {
      + app_network_access_type                        = "PublicInternetOnly"
      + arn                                            = (known after apply)
      + auth_mode                                      = "IAM"
      + domain_name                                    = "test"
      + home_efs_file_system_id                        = (known after apply)
      + id                                             = (known after apply)
      + security_group_id_for_domain_boundary          = (known after apply)
      + single_sign_on_application_arn                 = (known after apply)
      + single_sign_on_managed_application_instance_id = (known after apply)
      + subnet_ids                                     = [
          + "subnet-yyyyyyyyyyy",
        ]
      + tags_all                                       = (known after apply)
      + url                                            = (known after apply)
      + vpc_id                                         = "vpc-vpc-xxxxxxxxxxxx"

      + default_user_settings {
          + default_landing_uri = (known after apply)
          + execution_role      = "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole"
          + studio_web_portal   = (known after apply)
        }

      + domain_settings {
          + r_studio_server_pro_domain_settings {
              + domain_execution_role_arn    = "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole"
              + r_studio_connect_url         = "https://connect.domain.com"
              + r_studio_package_manager_url = "https://package.domain.com"

              + default_resource_spec {
                  + instance_type       = "system"
                  + sagemaker_image_arn = "arn:aws:sagemaker:ca-central-1:310906938811:image/rstudio-workbench-2023.03"
                }
            }
        }

      + retention_policy {
          + home_efs_file_system = "Delete"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
aws_sagemaker_domain.rstudio: Creating...
aws_sagemaker_domain.rstudio: Still creating... [10s elapsed]
...
aws_sagemaker_domain.rstudio: Still creating... [4m20s elapsed]
aws_sagemaker_domain.rstudio: Still creating... [4m30s elapsed]
aws_sagemaker_domain.rstudio: Creation complete after 4m35s [id=d-sauslritkv2i]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Actual Behavior

However after creation we see this attribute missing on AWS Console or when describing the sage maker domain. On future terraform plans it shows as pending update:

aws_sagemaker_domain.rstudio: Refreshing state... [id=d-sauslritkv2i]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with
the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_sagemaker_domain.rstudio will be updated in-place
  ~ resource "aws_sagemaker_domain" "rstudio" {
        id                                             = "d-sauslritkv2i"
        tags                                           = {}
        # (14 unchanged attributes hidden)

      ~ domain_settings {
            # (2 unchanged attributes hidden)

          ~ r_studio_server_pro_domain_settings {
              + r_studio_package_manager_url = "https://package.domain.com"
                # (2 unchanged attributes hidden)

                # (1 unchanged block hidden)
            }
        }

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
aws_sagemaker_domain.rstudio: Modifying... [id=d-sauslritkv2i]
aws_sagemaker_domain.rstudio: Modifications complete after 3s [id=d-sauslritkv2i]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files


data "aws_partition" "current" {}

resource "aws_iam_role" "test" {
  name               = "sagemaker-domain-role"
  path               = "/"
  assume_role_policy = data.aws_iam_policy_document.test.json
  inline_policy {
    name   = "GetLicense"
    policy = data.aws_iam_policy_document.license.json
  }
}

data "aws_iam_policy_document" "test" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["sagemaker.${data.aws_partition.current.dns_suffix}"]
    }
  }
}

# needed for RStudio
data "aws_iam_policy_document" "license" {
  statement {
    sid    = "ReadLicense"
    effect = "Allow"
    actions = [
      "license-manager:ExtendLicenseConsumption",
      "license-manager:ListReceivedLicenses",
      "license-manager:GetLicense",
      "license-manager:CheckoutLicense",
      "license-manager:CheckInLicense",
    ]
    resources = ["*"]
  }
}

resource "aws_iam_role_policy_attachment" "test" {
  role       = aws_iam_role.test.name
  policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonSageMakerFullAccess"
}

resource "aws_sagemaker_domain" "rstudio" {
  domain_name = "test"
  auth_mode   = "IAM"
  vpc_id       = "vpc-vpc-xxxxxxxxxxxx" # PLEASE ADAPT
  subnet_ids  = ["subnet-yyyyyyyyyyy"] # PLEASE ADAPT

  domain_settings {

    r_studio_server_pro_domain_settings {
      r_studio_connect_url         = "https://connect.domain.com"
      r_studio_package_manager_url = "https://package.domain.com"
      domain_execution_role_arn    = aws_iam_role.test.arn
      default_resource_spec {
        instance_type                 = "system" 
       # default image: https://docs.aws.amazon.com/sagemaker/latest/dg/rstudio-version.html
       #  sagemaker_image_arn           = "arn:aws:sagemaker:ca-central-1:310906938811:image/rstudio-workbench-2023.03"
       }
    }
  }

  default_user_settings {
    execution_role = aws_iam_role.test.arn

  }

  retention_policy {
    home_efs_file_system = "Delete"
  }

  lifecycle {
    ignore_changes = [ 
        domain_settings[0].r_studio_server_pro_domain_settings[0].default_resource_spec[0]
     ]
  }
}

Steps to Reproduce

  1. Make sure you have the right license from Posit to use this RStudio: https://docs.aws.amazon.com/sagemaker/latest/dg/rstudio-license.html
  2. Create SageMaker domain with r_studio_package_manager_url
  3. Verify that Sagemaker Domain it's not present in domain when describing it: aws sagemaker describe-domain --domain-id d-xxxxxxx
  4. Do another terraform plan and see it's pending terraform plan
  5. Even after second terraform apply the attribute is still missing

Debug Output

No response

Panic Output

No response

Important Factoids

When tracing the API calls from AWS see. that this attribute It's ignored during API calls CloudTrail trace shows that the attribute wasn't received on AWS side:

{
    "eventVersion": "1.09",
    "userIdentity": {
        ...
    },
    "eventTime": "2024-07-25T22:34:58Z",
    "eventSource": "sagemaker.amazonaws.com",
    "eventName": "CreateDomain",
    "awsRegion": "ca-central-1",
    ...
    "requestParameters": {
        "domainName": "test",
        "authMode": "IAM",
        "defaultUserSettings": {
            "executionRole": "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole"
        },
        "domainSettings": {
            "rStudioServerProDomainSettings": {
                "domainExecutionRoleArn": "arn:aws:iam::zzzzzzzzzzzzzz:role/sagmakerDomainRole",
                "rStudioConnectUrl": "https://connect.domain.com",
                "defaultResourceSpec": {
                    "sageMakerImageArn": "arn:aws:sagemaker:ca-central-1:310906938811:image/rstudio-workbench-2023.03",
                    "instanceType": "system"
                }
            }
        },
        "subnetIds": [
            "subnet-yyyyyyyyyyy"
        ],
        "vpcId": "vpc-vpc-xxxxxxxxxxxx",
        "tags": [],
        "appNetworkAccessType": "PublicInternetOnly"
    },
    "responseElements": {
        "domainArn": "arn:aws:sagemaker:ca-central-1:zzzzzzzzzzzzzz:domain/d-sauslritkv2i",
        "url": "https://d-sauslritkv2i.studio.ca-central-1.sagemaker.aws"
    },
   ....
}

We only see rStudioConnectUrl attribute but no rStudioPackageManagerUrl The same is valid for UpdateDomain API call.

References

No response

Would you like to implement a fix?

Yes

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

felipempda commented 1 month ago

I've found the issue, it's a simple typo!

I've created a PR for this with an acceptance test. Thanks a lot!

github-actions[bot] commented 1 month ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 1 month ago

This functionality has been released in v5.61.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] commented 1 week ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.