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.86k stars 9.21k forks source link

[Bug]: Default `image_version_number` in `aws_sagemaker_domain` custom images should be 1, not 0 #37456

Open mritterfigma opened 6 months ago

mritterfigma commented 6 months ago

Terraform Core Version

1.8.3

AWS Provider Version

5.42.0

Affected Resource(s)

When specifying a custom_image inside a sagemaker_domain, the image_version_number field is optional. If you leave it out, the default is 0. Unfortunately, it is impossible to have a version number 0 in the AWS custom version system for Sagemaker Domains. This results in a successful apply but a setup that actually doesn't work (i.e. you can't start a JupyterLab Space from the image, for example).

The default should be 1 instead so that the configuration will be valid.

For example, consider the following snippet taken from the terraform docs:

resource "aws_sagemaker_image" "example" {
  image_name = "example"
  role_arn   = aws_iam_role.example.arn
}

resource "aws_sagemaker_app_image_config" "example" {
  app_image_config_name = "example"

  kernel_gateway_image_config {
    kernel_spec {
      name = "example"
    }
  }
}

resource "aws_sagemaker_image_version" "example" {
  image_name = aws_sagemaker_image.example.id
  base_image = "base-image"
}

resource "aws_sagemaker_domain" "example" {
  domain_name = "example"
  auth_mode   = "IAM"
  vpc_id      = aws_vpc.example.id
  subnet_ids  = [aws_subnet.example.id]

  default_user_settings {
    execution_role = aws_iam_role.example.arn

    kernel_gateway_app_settings {
      custom_image {
        app_image_config_name = aws_sagemaker_app_image_config.example.app_image_config_name
        image_name            = aws_sagemaker_image_version.example.image_name
      }
    }
  }
}

This configuration will not work because aws_sagemaker_image_version.example will have version 1, while kernel_gateway_app_settings.custom_image will have version 0

Expected Behavior

Default should be 1, not 0

Actual Behavior

Default of 0 results in successful apply but bad config

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_sagemaker_image" "example" {
  image_name = "example"
  role_arn   = aws_iam_role.example.arn
}

resource "aws_sagemaker_app_image_config" "example" {
  app_image_config_name = "example"
}

resource "aws_sagemaker_image_version" "example" {
  image_name = aws_sagemaker_image.example.id
  base_image = "base-image"
}

resource "aws_sagemaker_domain" "example" {
  domain_name = "example"
  auth_mode   = "IAM"
  vpc_id      = aws_vpc.example.id
  subnet_ids  = [aws_subnet.example.id]

  default_user_settings {
    execution_role = aws_iam_role.example.arn

    jupyter_lab_app_settings {
      custom_image {
        app_image_config_name = aws_sagemaker_app_image_config.example.app_image_config_name
        image_name            = aws_sagemaker_image_version.example.image_name
      }
    }
  }
}

Steps to Reproduce

  1. Paste example
  2. Apply
  3. Go to Sagemaker Studio. Try to start a JupyterLab Space with this image.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 6 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

minamijoyo commented 5 months ago

I checked a trace-level log and confirmed that the the UpdateDomain API request includes "ImageVersionNumber":0.

By the way, I think it's better to omit it If the ImageVersionNumber is not specified rather than implicitly setting default value as 0 or 1 because ImageVersionNumber is an optional field in the schema. https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CustomImage.html

When ImageVersionNumber isn't specified, the latest version of the image is used. https://docs.aws.amazon.com/sagemaker/latest/dg/studio-byoi-attach.html