Creating a Stack
Function
CreateStack creates a stack.
-
If template, vars, and other information are not included in the request, an empty stack will be created and stack_id will be returned.
-
If template, vars, and other information are included in the request, a stack will be created and stack_id and deployment_id will be returned.
-
If encrypt_kms_key_id is provided to enable template encryption, ensure that the stack agency role (if configured) or the current account identity has kms:dek:create(Create a data key) and kms:dek:decrypt(decrypt a data key) permissions to access the specified KMS master key.
URI
POST /v1/{project_id}/stacks
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | A project ID is obtained by calling an API or from the console. Minimum: 3 Maximum: 64 |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Client-Request-Id | Yes | String | A unique request ID is specified by a user to locate a request. UUID is recommended. Minimum: 36 Maximum: 128 |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| stack_name | Yes | String | A stack name is unique within its domain (domain_id), region, and project (project_id). It is case-sensitive and starts with a letter. Only letters, digits, underscores (_), and hyphens (-) are allowed. Minimum: 1 Maximum: 128 |
| agencies | No | Array of Agency objects | Agency information. RFS uses an agency only in requests that involve resource operations, such as creating a stack (triggering deployment), creating an execution plan, deploying a stack, and deleting a stack. In addition, the agency applies only to resource operations performed by the provider bound to the agency. If the permissions provided by the agency are insufficient, operations on related resources may fail. Creating Delegation and Authorisation Methods Array Length: 0 - 10 |
| description | No | String | Description of a stack. It can be used by customers to identify their own stacks. Minimum: 0 Maximum: 1024 |
| enable_deletion_protection | No | Boolean | Deletion protection flag. If this variable is not assigned, the default value is false, indicating that deletion protection is disabled by default. (After deletion protection is enabled, stacks cannot be deleted.) In the UpdateStack API, if this variable is not assigned in the RequestBody, the deletion protection attribute of the stack will not be updated. |
| enable_auto_rollback | No | Boolean | Auto-rollback flag. If this variable is not assigned, the default value is false, indicating that auto-rollback is disabled by default. (After auto-rollback is enabled, if the deployment fails, the stack is automatically rolled back and returns to the previous stable status.) In the UpdateStack API, if this variable is not assigned in the RequestBody, the auto-rollback attribute of the stack will not be updated. This property is mutually exclusive with the import resources using templates feature, which does not allow the deployment of templates containing imported resources if the stack's auto-rollback is set to true. |
| template_body | No | String | HCL template. It describes the target status of a resource. RFS compares the differences between the statuses of this template and the current remote resources. Exactly one of template_body, template_uri, or private_template must be specified. In the CreateStack API, template_body, template_uri and private_template are optional. Note:
(If a variable is marked as sensitive in the template, its value will be masked in the vars_structure, vars_uri_content, and vars_body fields returned by the GetStackMetadata and GetExecutionPlanMetadata APIs.) Minimum: 0 Maximum: 51200 |
| template_uri | No | String | OBS address of an HCL template. The template describes the target status of a resource. RFS compares the differences between the statuses of this template and the current remote resources. Ensure that the OBS address is located in the same region as the RFS. The corresponding file must be a tf file or a zip package. A pure .tf file must end with .tf or .tf.json and comply with the HCL syntax. Currently, only the .zip package is supported. The file name extension must be .zip. The decompressed file cannot contain the .tfvars file and must be encoded in UTF8 format (the .tf.json file cannot contain the BOM header). The .zip package supports a maximum of 100 subfiles. Exactly one of template_body, template_uri and private_template must be specified. In the CreateStack API, template_body, template_uri and private_template are optional. Note:
(If a variable is marked as sensitive in the template, its value will be masked in the vars_structure, vars_uri_content, and vars_body fields returned by the GetStackMetadata and GetExecutionPlanMetadata APIs.) Minimum: 0 Maximum: 2048 |
| vars_body | No | String | Content of the HCL variable file. Transferring variables is supported by the HCL template. The same template can use different variables for different purposes.
Minimum: 0 Maximum: 51200 |
| vars_structure | No | Array of VarsStructure objects | HCL variable structure. Transferring variables is supported by the HCL template. The same template can use different variables for different purposes.
Array Length: 0 - 100 |
| vars_uri | No | String | OBS address of the HCL variable file. Transferring variables is supported by the HCL template. The same template can use different variables for different purposes. Ensure that the OBS address is located in the same region as the RFS.
Minimum: 0 Maximum: 2048 |
| encrypt_kms_key_id | No | String | The ID of the KMS customer master key (CMK) used to encrypt templates. Currently, only keys using the AES-256 algorithm are supported. If specified, RFS will use this key to encrypt your Terraform templates for storage. Please note that using your own CMK may incur KMS service charges. Important: Exercise caution when deleting this CMK. Deleting a key that is in use will render the associated stacks inaccessible, and you assume all risks associated with this action. Minimum: 36 Maximum: 36 |
| private_template | No | PrivateTemplate object | |
| tags | No | Array of Tag objects | List of tags. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| provider_name | Yes | String | Name of the provider used by a user. If the provider_name value given by the user is duplicate, 400 is returned. Supported values: Minimum: 1 Maximum: 128 |
| agency_name | No | String | IAM agency used by the corresponding provider. RFS uses this agency to access and create resources of the provider. Either agency_name or agency_urn must be specified. Minimum: 1 Maximum: 64 |
| agency_urn | No | String | Agency URN When a user defines an agency, either agency_name or agency_urn must be specified. You are advised to set agency_urn when using the trust agency. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| var_key | Yes | String | Variable name. Minimum: 1 Maximum: 32 |
| var_value | Yes | String | Variable value. Variables must be in the form of a string. If a parameter is a number, it must also be in the form of a string, for example, '10'. For different types or complex structures, you can use vars_uri or vars_body. Minimum: 0 Maximum: 2048 |
| encryption | No | EncryptionStructure object | If a transferred var_value has been encrypted, you can declare this variable to require RFS to decrypt the var_value before using it. Currently, only KMS encryption and decryption are supported. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| kms | Yes | KmsStructure object | If an assigned var_value is encrypted by KMS, related encryption information can be transferred. RFS will help you decrypt the var_value by KMS. For more details about KMS encryption and its sample code, refer to KMS Application Scenarios. Note:
|
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | Yes | String | KMS key ID is used by RFS during decryption. Generally, the key ID is that used for encryption. Minimum: 36 Maximum: 36 |
| cipher_text | Yes | String | Ciphertext of data encryption key. Minimum: 2 Maximum: 2048 |
Response Parameters
Status code: 201
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 409
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 429
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
Example Requests
-
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/stacks { "stack_name" : "my_first_stack", "description" : "my first stack" } -
Create a stack using an agency.
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/stacks { "stack_name" : "my_second_stack", "description" : "my second stack", "agencies" : [ { "provider_name" : "huaweicloud", "agency_name" : "my_agency" } ] } -
Create and deploy a stack using the URI of a template.
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/stacks { "stack_name" : "my_third_stack", "template_uri" : "https://my_hello_world_bucket.{region}.myhuaweicloud.com/my-hello-world-template.tf", "description" : "my third stack" } -
Create and deploy a stack using a template. RFS supports the HCL syntax, and source field of required_providers module, which is used to define provider path, should be as the format of huawei.com/provider/{provider_name} (for example: huawei.com/provider/huaweicloud).
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/stacks { "stack_name" : "my_fourth_stack", "template_body" : "terraform {\n required_providers {\n huaweicloud = {\n source = \"huawei.com/provider/huaweicloud\"\n version = \"1.41.0\"\n }\n }\n}\nprovider \"huaweicloud\"{\n insecure = true\n cloud = \"{cloud_name}\"\n region = \"{region}\"\n endpoints = {\n iam = \"{iam_endpoint}\"\n }\n}\n\nresource \"huaweicloud_vpc\" \"vpc\" {\n cidr = \"172.16.0.0/16\"\n name = \"my_vpc\"\n}", "description" : "my fourth stack" } -
Create and deploy a stack using private template.
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/stacks { "stack_name" : "my_fifth_stack", "private_template" : { "template_id" : "69f8d5ea-eaa4-4a3b-a96d-bae9230e97c9", "template_version" : "V1" } }
Example Responses
Status code: 201
Stack created.
-
{ "stack_id" : "ea6a4f0e-ee8a-494e-b12a-8be4a1e65af2" } -
Create a stack using an agency.
{ "stack_id" : "ea6a4f0e-ee8a-494e-b12a-8be4a1e65af2" } -
Create and deploy a stack using the URI of a template.
{ "stack_id" : "ea6a4f0e-ee8a-494e-b12a-8be4a1e65af2", "deployment_id" : "d102dda3-10af-48db-75bb-16c2661c79d6" } -
Create and deploy a stack using a template. RFS supports the HCL syntax, and source field of required_providers module, which is used to define provider path, should be as the format of huawei.com/provider/{provider_name} (for example: huawei.com/provider/huaweicloud).
{ "stack_id" : "ea6a4f0e-ee8a-494e-b12a-8be4a1e65af2", "deployment_id" : "d102dda3-10af-48db-75bb-16c2661c79d6" } -
Create and deploy a stack using private template.
{ "stack_id" : "ea6a4f0e-ee8a-494e-b12a-8be4a1e65af2", "deployment_id" : "d102dda3-10af-48db-75bb-16c2661c79d6" }
Status Codes
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.