更新工作空间
更新现有工作空间的详细信息,例如工作空间名称、变量或源代码控制 URL。 要配置或修改 IBM Cloud,请参阅 ibmcloud schematics plan 命令。
IBM Cloud Schematics 不推荐使用旧版本的 Terraform。 有关更多信息,请参阅 在 IBM Cloud Schematics。
IBM Cloud Schematics 不推荐使用 2024 年 4 月 2nd 周的 IBM Cloud Provider Plug-in for Terraform v1.2和 v1.3 模板来创建工作空间。
准备工作
在创建或更新 Schematics 工作空间或操作时,请确保 location
和 url
端点指向同一区域。 有关位置和端点的更多信息,请参阅 信息存储位置?
使用 UI 更新工作空间
- 登录 IBM Cloud控制台。
- 单击菜单图标
>平台自动化>Schematics>Terraform。
- 点击您的工作区进行编辑。
- 单击设置。 在 “详细信息 > 资源库 URL”中,点击 “编辑” 图标编辑以下参数。
-
GitHub, GitLab, 或
Bitbucket
资料库 URL<provide your Terraform template Git repository URL
。 -
个人访问令牌
<leave it blank>
。 为了安全验证和克隆模板,您可以点击Open reference picker
选择您的 Secrets Manager 密钥参考。 更多信息,请参阅 创建 Secrets Manager 实例。 -
Terraform版本:
terraform_v1.6
。 您需要选择Terraform版本 1.6 或更高版本。 例如,如果您的Terraform模板是通过Terraform v1.6 创建的,请选择Terraform version
参数为 terraform_v1.6。 您可以选择Terraform_v1.4
来使用Terraform版本 1.4,选择terraform_v1.6
来使用Terraform版本 1.6。 当您指定terraform_v1.5
时,用户可以使用 Terraformv1.5.0
、v1.5.1
或v1.5.7
等模板。 Schematics 支持Terraform_v1.x
,并计划在30 to 45 days
HashiCorp 配置语言(HCL)版本发布后发布版本。Schematics 通过
terraform_v1.6
支持Terraform v1.4
的当前发行版。 Terraform 模板必须使用版本约束 (例如,>
,>=
或~>
表示 Terraform 的required_version
) 来自动选取当前版本。terraform { required_version = "~> 1.5" }
-
单击保存。
-
在变量部分。 点击浮动菜单中的 “编辑” 即可编辑变量。 输入
workspace name
的名称。 该名称最多可以为 128 个字符,可包含字母数字字符、空间、短划线和下划线。 -
单击保存。
-
验证工作空间更新
- 单击 IBM Cloud 控制台 中列出的工作空间,以查看工作空间详细信息的结果。
- 单击 作业 选项卡以查看工作空间日志。
- 单击 作业历史记录 选项卡以查看自动化模块运行的更新作业操作的结果。
- 单击 设置 选项卡以查看配置的摘要。
使用 CLI 更新工作空间
-
更新本地工作站上的 JSON 文件并添加工作空间配置。 有关更新工作空间时的更多配置选项,请参阅
ibmcloud schematics workspace update
命令。```json {: codeblock} { "name":"testwspace03jan", "type":[ "terraform_v1.4" ], "description":"terraform workspace", "location":"us-east", "tags":[ "department:HR", "application:compensation", "environment:production" ], "template_repo":{ "url":"https://github.com/Anil-CM/newrepo" }, "workspace_status":{ "frozen":true }, "template_data":[ { "folder":".", "type":"terraform_v1.4", "variablestore":[ { "name":"sample_var", "secure":true, "value":"THIS IS IBM CLOUD TERRAFORM CLI DEMO", "description":"Description of sample_var" }, { "name":"sleepy_time", "value":"15" } ] } ] } ```
语法
```sh {: pre} ibmcloud schematics workspace update --id WORKSPACE_ID [--file FILE_NAME] [--github-token GITHUB_TOKEN] [--pull-latest] [--output OUTPUT] ```
-
更新现有工作区的详细信息,如工作区名称、变量或源代码控制 URL。
```sh {: pre} ibmcloud schematics workspace update --id <WORKSPACE_ID> ```
-
验证您的工作空间是否已更新。 确保工作空间处于 不活动 状态。
```sh {: pre} ibmcloud schematics workspace list ```
-
请参考 《 使用 Schematics 管理云资源 》,开始使用Terraform创建、更新或删除云资源。
验证工作空间更新
使用 CLI 命令 update 确认详细信息,其中已成功更新先前创建的工作空间的参数。
```text {: screen}
ibmcloud schematics workspace update --id us-east.workspace.testwspace03jan.811182d2 --target vpc_name --target vpc_tags
Do you really want to perform this action? [y/N]> y
Activity ID c10fc92ddfd2d9ec645fc5dbece5e341
OK
```
成功更新时,将返回现有工作空间的已更新详细信息。
有关更多信息,请参阅 故障诊断部分。
使用 API 更新工作空间
-
执行 步骤 以检索 IAM 访问令牌并使用 API 向 IBM Cloud Schematics 进行认证。
-
更新现有工作区的详细信息,如工作区名称、变量或源代码控制 URL。
示例
```json {: codeblock} PUT /v1/workspaces/{w_id} HTTP/1.1 Host: schematics.cloud.ibm.com Content-Type: application/json Authorization: <auth_token> { "name":"testwspace03jan", "type":[ "terraform_v1.4" ], "description":"terraform workspace updated", "location":"us-east", "tags":[ "department:HR", "application:compensation", "environment:production" ], "template_repo":{ "url":"https://github.com/Anil-CM/newrepo" }, "workspace_status":{ "frozen":true }, "template_data":[ { "folder":".", "type":"terraform_v1.4", "variablestore":[ { "name":"sample_var", "secure":true, "value":"THIS IS IBM CLOUD TERRAFORM CLI DEMO", "description":"Description of sample_var" }, { "name":"sleepy_time", "value":"15" } ] } ] } ```
-
验证是否已成功更新工作空间。
```sh {: pre} curl -X GET https://schematics.cloud.ibm.com/v1/workspaces -H "Authorization: <iam_access_token>" ```
-
请参阅 使用 Schematics 管理云资源,开始使用Terraform创建、更新或删除云资源。
验证工作空间更新
验证工作空间更新是否成功,如输出中所示。
输出
```text {: screen}
{
"id": "us-east.workspace.testwspace03jan.cf74cc48",
"name": "testwspace03jan",
"crn": "crn:v1:bluemix:public:schematics:us-south:a/1f7277194bb748cdb1d35fd8fb85a7cb:9ae7be42-0d59-415c-a6ce-0b662f520a4d:workspace:us-east.workspace.testwspace03jan.cf74cc48",
"type": [
"terraform_v1.4"
],
"description": "terraform workspace updated successfully",
"resource_group": "Default",
"location": "us-east",
"tags": [
"department:HR",
"application:compensation",
"environment:production"
],
"created_at": "2023-01-03T07:02:38.369965717Z",
"created_by": "test@in.ibm.com",
"status": "DRAFT",
"failure_reason": "",
"workspace_status_msg": {
"status_code": "200",
"status_msg": ""
},
"workspace_status": {
"frozen": true,
"frozen_by": "test@in.ibm.com",
"frozen_at": "2023-01-05T13:44:32.400019282Z",
"locked": false
},
"template_repo": {
"url": "https://github.com/Anil-CM/newrepo",
"commit_id": "3dc60ea7fb30f236dbadfa817cf4beb5d337808d",
"full_url": "https://github.com/Anil-CM/newrepo",
"has_uploadedgitrepotar": false
},
"template_data": [
{
"id": "b44c147b-81fb-4e",
"folder": ".",
"compact": false,
"type": "terraform_v1.4",
"values_url": "https://us.schematics.cloud.ibm.com/v1/workspaces/us-east.workspace.testwspace03jan.cf74cc48/template_data/b44c147b-81fb-4e/values",
"values": "",
"values_metadata": [
{
"default": "testvpcone",
"description": "",
"name": "vpc_name",
"type": "string"
},
{
"default": "[\"tag:test1\", \"tag:test2\"]",
"description": "",
"name": "vpc_tags",
"type": "list(string)"
}
],
"variablestore": [
{
"name": "sample_var",
"secure": true,
"value": "THIS IS IBM CLOUD TERRAFORM CLI DEMO",
"type": "",
"description": "Description of sample_var"
},
{
"name": "sleepy_time",
"secure": false,
"value": "15",
"type": "",
"description": ""
}
],
"has_githubtoken": false
}
],
"runtime_data": [
{
"id": "b44c147b-81fb-4e",
"engine_name": "terraform",
"engine_version": "v1.0.11",
"state_store_url": "https://us.schematics.cloud.ibm.com/v1/workspaces/us-east.workspace.testwspace03jan.cf74cc48/runtime_data/b44c147b-81fb-4e/state_store",
"log_store_url": "https://us.schematics.cloud.ibm.com/v1/workspaces/us-east.workspace.testwspace03jan.cf74cc48/runtime_data/b44c147b-81fb-4e/log_store"
}
],
"shared_data": {
"resource_group_id": ""
},
"applied_shareddata_ids": null,
"updated_by": "test@in.ibm.com",
"updated_at": "2023-01-05T13:44:32.483034358Z",
"last_health_check_at": "0001-01-01T00:00:00Z",
"cart_id": "",
"last_action_name": "WORKSPACE_UPDATE",
"last_activity_id": "fe1591c02c66167b41fefac1ab5445cb",
"last_job": {
"job_id": "fe1591c02c66167b41fefac1ab5445cb",
"job_name": "WORKSPACE_UPDATE",
"job_status": ""
}
}
```
成功更新工作区后,它会返回更新配置的详细信息,例如工作区名称、变量或工作区源代码URL。
有关更多信息,请参阅 故障诊断部分。
使用 Terraform 更新工作空间
-
遵循 为 Schematics 中的步骤以使用 Terraform 创建工作空间。
-
请参阅 使用 Schematics 管理云资源,使用Terraform创建、更新或删除云资源。
后续步骤
使用工作区的下一阶段是 部署工作区。