The template synchronization feature lets you manage stacks by using a code repository. Changes to a file in the code repository automatically update the stack.
Prerequisites
-
Authorize Compute Nest to access your GitHub account. If you are using this feature for the first time, you must grant authorization on GitHub before selecting a repository user.
On the Create Stack page, select Sync Template from Code Repository and choose GitHub as the repository platform. If you have not granted authorization, a warning appears at the bottom of the page. Click Go to authorize.
-
Grant the AppFlow service the required permissions to update stacks. For more information about the required permissions, see AliyunServiceRoleForAppFlow.
Procedure
Step 1: Write the template and configuration file
-
Write a Terraform or Resource Orchestration Service (ROS) template. This example uses a ROS template that creates a VPC. You can customize templates with AI Template Assistant or use Visual Editor to write templates.
ROSTemplateFormatVersion: "2015-09-01" Parameters: VpcName: Type: String Default: git-demo Resources: Vpc: Type: ALIYUN::ECS::VPC Properties: VpcName: Ref: VpcName CidrBlock: 192.168.0.0/16 Outputs: VpcId: Value: Ref: Vpc -
Write a configuration file in JSON or YAML format. This example uses
my-vpc-demo.yaml.The following list describes the structure of the configuration file:
-
template-file-path: The path to the Terraform or ROS template file. -
parameters: The parameters required for deployment. -
tags: The tags to apply during deployment.
template-file-path: templates/my-vpc-demo.yaml parameters: VpcName: git-demo-1 tags: env: test -
Step 2: Upload files to the repository
Log on to GitHub and upload the template and configuration file to your repository. The directory structure is as follows:
.
├── my-vpc-config.yaml
└── templates
└── my-vpc-demo.yaml
Step 3: Create a stack
-
Go to the Resource Orchestration - Stacks page and click Create Stack.
-
On the Select Template page, set Specify Template to Sync Template from Code Repository.
-
For Repository Platform, select GitHub. Then, select the repository user, repository name, and repository branch for the repository that you used in Step 2.
-
Select your Template Type. This section uses a ROS template as an example.
Select the Sync Template from Code Repository tab. For Repository Platform, select GitHub, and then configure Repository User, Repository Name, and Repository Branch. To link your GitHub account, click Go to authorize.
-
Choose whether to enable Automatically Update Stack. This example uses the Enable setting.
The stack updates automatically when files in the code repository change.
-
Enable: An empty stack is created initially. After the stack is created, you can click Run in the Code Repository Information section to run an initial synchronization and update.
-
Disable: Select an existing template from the code repository.
-
-
For Configuration File Path, select the configuration file you uploaded to the GitHub repository. The console automatically loads the content of the file.
Turn on the Automatically Update Stack switch. In this example, the selected configuration file is
my-vpc-config.yaml. Its YAML content includes atemplate-file-pathoftemplates/my-vpc-demo.yaml, aVpcNameparameter set togit-demo-1, and anenvtag set totest. -
Click Next. On the Configure Parameters page, enter the parameters as needed. Click Create. You are redirected to the Code Repository Information tab.
Automatic synchronization is now configured. When you change the template or configuration file in your GitHub repository, the stack is updated automatically.
Step 4: Update the stack
Update now
-
To trigger an immediate update, click Run in the upper-right corner.
-
Wait until the Status in the automatic update logs changes to Succeeded. Then, on the Resources tab, verify that the VPC was created.
-
Go to the VPC Console and verify that a VPC instance named git-demo-1 exists.
Modify files to update the stack
This example updates the configuration file by changing the VPC name from git-demo-1 to git-demo-2.
-
Log on to GitHub and go to the repository from Step 2. In the
my-vpc-config.yamlfile, changegit-demo-1togit-demo-2, and then merge the change into the branch.template-file-path: templates/my-vpc-demo.yaml parameters: VpcName: git-demo-2 tags: env: test -
Go to the Resource Orchestration - Stacks page, select the target stack, and on the Events tab, the update events for the VPC are displayed.
-
When the stack update is complete, go to the VPC console. The name of the VPC has been updated from
git-demo-1togit-demo-2.