You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform报错:无法将Git仓库添加至AWS SageMaker空间

问题:Terraform配置SageMaker Space添加Git仓库报错

执行terraform apply时出现如下错误:

│ Error: updating SageMaker Space: ValidationException: Unknown parameter CodeRepositories in JupyterServerAppSettings for SpaceSettings.
│   status code: 400, request id: 492c767a-ad2b-4cd3-b0e8-d3b402d43a00
│ 
│   with module.sagemaker_studio_notebooks.aws_sagemaker_space.this,
│   on ../modules/sagemaker-studio-notebooks/main.tf line 65, in resource "aws_sagemaker_space" "this":
│   65: resource "aws_sagemaker_space" "this" {

该问题在空间创建与修改操作时均会出现。

相关代码

代码仓库资源配置

resource "aws_sagemaker_code_repository" "this" {
  code_repository_name = "this-code-repo"

  git_config {
    repository_url = local.repo_url
    secret_arn = aws_secretsmanager_secret.github_login_token.arn
  }

  depends_on = [
    aws_secretsmanager_secret_version.github_login_token,
  ]
}

SageMaker Space资源配置

resource "aws_sagemaker_space" "this" {
  domain_id = aws_sagemaker_domain.this.id
  space_name = "my-space-name"

  space_settings {
    jupyter_server_app_settings {
      default_resource_spec {
        instance_type = "system"
      }

      code_repository {
        repository_url = local.repo_url
      }
    }
  }
}

Terraform后端配置

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 5.21.0"
    }
  }

  required_version = ">= 1.6.0"
}

已在AWS控制台中确认关联的Git仓库已存在。


解决方案

你的配置错误在于将code_repository参数放在了jupyter_server_app_settings块内,Terraform AWS Provider 5.21.0版本中,aws_sagemaker_space资源的jupyter_server_app_settings并不支持该参数——这个参数仅适用于Domain级别的JupyterServer配置,而非Space级别。

正确的做法是在space_settings块下直接使用code_repositories,关联已创建的aws_sagemaker_code_repository资源名称:

修改后的aws_sagemaker_space配置:

resource "aws_sagemaker_space" "this" {
  domain_id   = aws_sagemaker_domain.this.id
  space_name  = "my-space-name"

  space_settings {
    jupyter_server_app_settings {
      default_resource_spec {
        instance_type = "system"
      }
    }

    # 直接在space_settings下配置代码仓库关联
    code_repositories {
      code_repository_name = aws_sagemaker_code_repository.this.code_repository_name
    }
  }
}

说明:

  • Space级别通过space_settings.code_repositories关联已创建的代码仓库资源,而非嵌套在JupyterServer配置内
  • 引用已创建的aws_sagemaker_code_repository的名称,现有depends_on配置已确保依赖关系正确,无需额外调整

内容的提问来源于stack exchange,提问作者nerdlinger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 08:07:42