Updated on 2024-12-12 GMT+08:00

Create a Private Module

Function

Create a Private Module (CreatePrivateModule)

This API creates a private empty module. If you specify module_version and module_uri, a private module version will be created along with the private module.

  • Modules allow you to bundle reusable code together.

  • If a private module with the same name already exists in the current account, an error message will be returned.

  • Each version number can be defined by following the semantic versioning format.

  • RFS conducts basic validations on modules, including file size, decompression capability, and number of files. However, it does not perform detailed verification, such as syntax checking.

The following example is a HCL-formatted template, which shows how to reference a private module:

module "my_hello_word_module" {
  source = "rf://rfs.{region_id}.myhuaweicloud.com/private/{domain_id}/{module_name}?version=={module_version}"
}

The following example is a JSON-formatted template, which shows how to reference a private module using the correct syntax:

{
  "module": {
    "my_hello_word_module": {
      "source": "rf://rfs.{region_id}.myhuaweicloud.com/private/{domain_id}/{module_name}?version=={module_version}"
    }
  }
}

The module URLs (value of the source field) in the previous two examples come from the module_source field, which can be obtained by calling the ShowPrivateModuleVersionMetadata API.

URI

POST /v1/private-modules

Request Parameters

Table 1 Request header 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.

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

module_name

Yes

String

Name of a private module. The name is unique within its domain (domain_id) and region. Only letters, digits, underscores (_), and hyphens (-) are allowed. It is case-sensitive and must start with a letter.

module_version

No

String

Module version number. Each version number can be defined by following the semantic versioning format.

module_description

No

String

Description of a private module. It serves as an identifier for you to recognize managed private modules. To update the description of a private module, call the UpdatePrivateModuleMetadata API.

module_uri

No

String

Address for accessing the module package in OBS. Modules allow you to bundle reusable code together.

The OBS address can be accessed across regions of the same type. Regions are classified into universal regions and dedicated regions. A universal region provides universal cloud services for common tenants. A dedicated region provides specific services for specific tenants.

The module package must be ZIP-formatted. To ensure the validity of the module package, the module package:

  • Cannot contain files whose names end with .tfvars.

  • Cannot exceed 1 MB in size before and after decompression.

  • Cannot contain more than 100 files.

  • Cannot contain file paths starting with a forward slash (/).

  • Disallow spaces, single periods (.), or double periods (..) between separators in file paths.

  • Allow each file path to be up to 2048 characters long.

  • Allow each file name to be up to 255 characters long.

  • Must include at least one template file (whose name ends with .tf or .tf.json).

Notes:

  • Modules do not support encryption for sensitive data. The module package associated with the module_uri is used, logged, displayed, and stored in plaintext by RFS.

version_description

No

String

Description of a module version. It serves as an identifier for you to recognize and manage module versions. Note: A module version is immutable and cannot have its description updated. You can only delete the current version and create another one with the desired description.

Response Parameters

Status code: 201

Table 3 Response body parameters

Parameter

Type

Description

module_id

String

Unique ID of a private module.

It is a UUID generated by RFS when a module is created.

Private module names are unique only at a specific time, so you can create a private module named HelloWorld and another private module with the same name after deleting the first one.

For parallel development, team members may want to ensure that they are operating the private module they created, not the one with the same name created by other members after deleting the previous one.

To avoid this mismatch, check the ID, since RFS ensures each private module has a unique ID that does not change with updates. If the module_id differs from the current module ID, error code 400 is returned.

Status code: 400

Table 4 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 5 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 7 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Status code: 403

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 9 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Status code: 409

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 11 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Status code: 429

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 13 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Status code: 500

Table 14 Response body parameters

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

encoded_authorization_message

String

The message contains information about unauthorized requests.

details

Array of Detail objects

Detailed error information. It is returned by the service when the "permission denied" error occurs.

Table 15 Detail

Parameter

Type

Description

error_code

String

Response code.

error_msg

String

Response message.

Example Requests

None

Example Responses

None

Status Codes

Status Code

Description

201

The private module is created.

400

Invalid request.

401

Authentication failed.

403

  1. The user does not have the permission to call this API.

  2. The maximum number of private module has been reached.

409

Creation request conflict. The specified private module already exists.

429

Too frequent requests.

500

Internal server error.