Terraform integration example
Terraform is an open source tool that you can use to securely and efficiently provision and manage cloud infrastructure. You can use Terraform to manage Service Catalog resources. This topic provides an example of how to create a product portfolio using Terraform.
Supported resources
The following is a partial list of resources and data sources that support Terraform orchestration for Service Catalog. For more information, see Service Catalog Terraform resources and data sources. If you are new to Terraform, see Introduction to Terraform.
Resource type |
Resource link |
Description |
Resources |
Creates a product portfolio. |
|
Launches a product. |
||
Data Sources |
The end user sends a query to the product. |
|
Queries launch options. |
||
Queries product portfolios. |
||
Queries product versions. |
||
Queries provisioned products. |
Procedure
Configure permissions
To execute a Terraform template, you need the permissions of a Resource Access Management (RAM) user. Create a RAM user, obtain an AccessKey, and add an access policy. Set this AccessKey as an environment variable for Terraform. Add the following permission to the RAM user:
AliyunServiceCatalogAdminFullAccess: The administrator permissions to manage Service Catalog resources.
An Alibaba Cloud account has access permissions for all APIs, which poses a high security risk. We recommend that you create and use a RAM user for API access or daily O&M. Grant permissions as needed before you make API calls. The RAM user must have the permissions to manage Service Catalog resources. For more information, see Use RAM for access control.
Install Terraform
To install and configure Terraform locally, see Install and configure Terraform locally.
After the installation is complete, open a command-line terminal and run the
terraform versioncommand. If version information is returned, the installation is successful.If you do not want to install Terraform locally, you can use Cloud Shell. Cloud Shell is an online service from Alibaba Cloud that provides a built-in Terraform runtime environment.
Write the template
Create a file named main.tf and add the following content to create a product portfolio.
provider "alicloud" {
region = "cn-hangzhou"
}
variable "name" {
default = "tf_example"
}
resource "alicloud_service_catalog_portfolio" "default" {
portfolio_name = var.name
provider_name = var.name
}
For more information about the configuration of the alicloud_service_catalog_portfolio resource type, see Service Catalog Terraform resources and data sources.
Run the template
This example uses the Windows operating system. The commands may vary based on your operating system.
Initialize the modules, including the provider.
terraform init
Validate the template syntax.
terraform validate
Create an execution plan.
terraform plan
Deploy the template.
terraform applyAfter you run the command, enter
yesto apply the changes to the resources. Run theterraform destroycommand to release the resources created by the template.Verify that the operation is complete using OpenAPI, an SDK, or the Service Catalog console.