package main
import ( "fmt" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" tic "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tic/v20201117" "time" )
func describeStacks(client *tic.Client) []*tic.StackInfo { request := tic.NewDescribeStacksRequest() response, err := client.DescribeStacks(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return nil } if err != nil { panic(err) } return response.Response.Stacks }
func createStack(client *tic.Client, name, region, templateUrl string) *string { request := tic.NewCreateStackRequest() request.StackName = common.StringPtr(name) request.StackRegion = common.StringPtr(region) request.TemplateUrl = common.StringPtr(templateUrl)
response, err := client.CreateStack(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return nil } if err != nil { panic(err) } return response.Response.StackId }
func deleteStack(client *tic.Client, stackId string) { request := tic.NewDeleteStackRequest() request.StackId = common.StringPtr(stackId)
_, err := client.DeleteStack(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return } if err != nil { panic(err) } }
func describeStackVersions(client *tic.Client) []*tic.VersionInfo { request := tic.NewDescribeStackVersionsRequest()
response, err := client.DescribeStackVersions(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return nil } if err != nil { panic(err) } return response.Response.Versions }
func planStack(client *tic.Client, stackId, versionId string) *string { request := tic.NewPlanStackRequest() request.StackId = common.StringPtr(stackId) request.VersionId = common.StringPtr(versionId)
response, err := client.PlanStack(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return nil } if err != nil { panic(err) } fmt.Printf("%s\n", response.ToJsonString()) return response.Response.EventId }
func applyStack(client *tic.Client, stackId, versionId string) { request := tic.NewApplyStackRequest() request.StackId = common.StringPtr(stackId) request.VersionId = common.StringPtr(versionId)
response, err := client.ApplyStack(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return } if err != nil { panic(err) } fmt.Printf("%s", response.ToJsonString()) }
func describeStackEvent(client *tic.Client, eventId string) string { request := tic.NewDescribeStackEventRequest() request.EventId = common.StringPtr(eventId)
response, err := client.DescribeStackEvent(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return "" } if err != nil { panic(err) } return *response.Response.Status }
func main() { credential := common.NewCredential( "SecretId", "SecretKey", ) cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = "tic.tencentcloudapi.com" client, _ := tic.NewClient(credential, "", cpf) region := "ap-shanghai"
stacks := describeStacks(client) for _, stack := range stacks { deleteStack(client, *stack.StackId) } createStack(client, "demo", region, "") versions := describeStackVersions(client) for _, version := range versions { fmt.Println(*version.StackId, *version.VersionId, *version.VersionName) planStack(client, *version.StackId, *version.VersionId) time.Sleep(time.Second * 30) applyStack(client, *version.StackId, *version.VersionId) } }
|