To create a cloud template, you make a POST request. The request body includes the name of the new cloud template and the project ID of an existing project. To update a cloud template, you make a PUT request that changes one of the properties of the cloud template.
Before creating a cloud template, you get a list of cloud templates to verify that the cloud template you plan to create does not already exist. After a cloud template is created, you can update it to change the cloud template definition.
Prerequisites
- Verify that all general prerequisites and prerequisites for the Cloud Assembly Blueprint service have been satisfied. See Prerequisites for API Use Case Examples.
- Verify that you have a project ID for the project that includes cloud zones configured to support the resource requirements of your cloud template. See Create a Project to use in Cloud Assembly.
Procedure
Example: Create a Cloud Template and Update it
Create a cloud template named MyExampleCloudTemplate. This example assumes that MyExampleCloudTemplate does not already exist.
Assign variables.
$ url='https://appliance.domain.com' $ api_version='2019-09-12' $ project_id='394a4ccb-22c6-4ef0-8c75-8b77efbefb51' $ cloud_template_name='MyExampleCloudTemplate'
Validate the cloud template.
$ curl -X POST \ $url/blueprint/api/blueprint-validation?apiVersion=$api_version \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "name" : "'"$cloud_template_name"'", "description" : "Basic cloud machine cloud template", "content" : "formatVersion: 1\ninputs:\n flavor:\n type: string\n title: Flavor\n description: Flavor Mapping Name\n image:\n type: string\n title: Image\n description: Image Mapping Name\n count:\n type: integer\n minimum: 1\n default: 1\n maximum: 2\n title: Number of Instances\nresources:\n BasicCloudMachine:\n type: Cloud.Machine\n properties:\n name: BasicCloudMachine\n flavor: '\''${input.flavor}'\'' \n image: '\''${input.image}'\''\n count: '\''${input.count}'\''", "projectId" : "'"$project_id"'", "requestScopeOrg": false }' | jq "."
Examine the response to confirm that "valid":true.
{ "valid": true, "validationMessages": [] }
Create the cloud template.
$ curl -X POST \ $url/blueprint/api/blueprints?apiVersion=$api_version \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "name" : "'"$cloud_template_name"'", "description" : "Basic cloud machine cloud template", "content" : "formatVersion: 1\ninputs:\n flavor:\n type: string\n title: Flavor\n description: Flavor Mapping Name\n image:\n type: string\n title: Image\n description: Image Mapping Name\n count:\n type: integer\n minimum: 1\n default: 1\n maximum: 2\n title: Number of Instances\nresources:\n BasicCloudMachine:\n type: Cloud.Machine\n properties:\n name: BasicCloudMachine\n flavor: '\''${input.flavor}'\'' \n image: '\''${input.image}'\''\n count: '\''${input.count}'\''", "projectId" : "'"$project_id"'", "requestScopeOrg": false }' | jq "."
The response from your request to create the cloud template shows the cloud template ID.
{ "id": "1f170637-81a3-4257-b1cd-b2219ee8034c", "createdAt": "2019-10-10T23:43:27.001Z", ... "selfLink": "/blueprint/api/blueprints/1f170637-81a3-4257-b1cd-b2219ee8034c" ... }
Assign the cloud template ID variable.
$ cloud_template_id='1f170637-81a3-4257-b1cd-b2219ee8034c'
Update the cloud template to set a tag on the machine properties in the cloud template.
$ curl -X PUT \ $url/blueprint/api/blueprints/$cloud_template_id?apiVersion=$api_version \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "name" : "'"$cloud_template_name"'", "description" : "Basic cloud machine cloud template", "content" : "formatVersion: 1\ninputs:\n flavor:\n type: string\n title: Flavor\n description: Flavor Mapping Name\n image:\n type: string\n title: Image\n description: Image Mapping Name\n count:\n type: integer\n minimum: 1\n default: 1\n maximum: 2\n title: Number of Instances\nresources:\n BasicCloudMachine:\n type: Cloud.Machine\n properties:\n name: BasicCloudMachine\n flavor: '\''${input.flavor}'\'' \n image: '\''${input.image}'\''\n count: '\''${input.count}'\''\n tags: [\n {\n \"key\": \"env\",\n \"value\": \"prod\"\n }\n ]\n", "projectId" : "'"$project_id"'", "requestScopeOrg": false }' | jq "."
What to do next
Use the cloud template ID to version and release the cloud template to a catalog.