diff --git a/go.mod b/go.mod index fc179f61e..151f2ac10 100644 --- a/go.mod +++ b/go.mod @@ -370,6 +370,8 @@ require ( github.com/mailru/easyjson v0.7.6 // indirect github.com/manicminer/hamilton-autorest v0.2.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.617 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.617 // indirect k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect ) @@ -383,15 +385,19 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.392 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.617 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.392 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.604 // indirect github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.392 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.392 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.611 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.604 // indirect + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.606 // indirect github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.392 ) diff --git a/go.sum b/go.sum index 444039efa..1a9091eff 100644 --- a/go.sum +++ b/go.sum @@ -1314,6 +1314,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/tencentcloud/tencentcloud-sdk-go v1.0.392 h1:e5LzXdTogMU1aMaDjVSp1NYSZ594ZknqB3cw/0F9aZY= github.com/tencentcloud/tencentcloud-sdk-go v1.0.392/go.mod h1:l8PU0g9KTDkwn6R4F9WbXXSUwRgKs6k7rj52H4uAcM0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/aa v1.0.392/go.mod h1:DTrc+dJQjeL+2b7KEkfW1RiZqssiHxIMjRWhnt6PmU4= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/aai v1.0.392/go.mod h1:6jmvX/9tx9LoT7lireq2bULrcmgenqF9l4UQdzo143w= @@ -1377,6 +1378,14 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cms v1.0.392/go.mod h1: github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392 h1:UqcmPErxEm77NwqaRq6J1i2rcbhXcZHzq7WOuc9clAQ= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.604 h1:BiuYcs8fINjZT9omCf8tV+rZkrZdf+Hq4TMWUNqYNgY= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.604/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.606 h1:3Y3xlzSikB9BfKIfrTXQpwzeW97cxetqyq1kuMaMc08= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.606/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.611 h1:lAsu5kMPUpBhIo9/7VgFUH/pMgXNCwCsntTmwu1HSKY= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.611/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.617 h1:/4x3HGz3UK/ESYJj5xzPgGu7Nn9UIhAkvDe7s8/ZECY= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.617/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cpdp v1.0.392/go.mod h1:McFISRmzeVkPd8qZQjQw870DARtJHjJZoHHYMkhYcZA= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cr v1.0.392/go.mod h1:GZTyhAIbF0jhh76vReDXBXqd2+xfI4Fl8bM1mlq6Elg= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.392 h1:nWW99NdwjHzoFiYzk+6QvVjituRpDSgGP33TX4XX+Jk= @@ -1460,6 +1469,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/partners v1.0.392/go.mo github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pds v1.0.392/go.mod h1:jVbtUhMGZwdYC5qPhhWlG5wLI/kqHns1aoJ/opH1gBI= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.392/go.mod h1:7/xJYJ+/2X1q40woYOEvhaDx1wcHwQ2ZTYPncFnMFeM= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.392/go.mod h1:L6ywKmxdqNziWG5piJdyN83gRS+KMOR2nsqoS5khtNI= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.604 h1:4r5qY7XYnZQc6WJhES+DYI3xIm3hy6/e24wHOqwjmKY= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.604/go.mod h1:EFvGO7HiyBG9IrbeVBOixX5WUQQ1RPAirGRWrl1eiIA= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rce v1.0.392/go.mod h1:Q+Lj6ujWGd0VijJRdmnisHn0/K5MHlDwETZ5UNoDXRU= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.392 h1:TWsBoGmj5VuGyHwCksgKxKrZIwVVwn5bTuDfRbWD/yY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.392/go.mod h1:kR0eQOu2//soHJHK8aDmIoU1f4jxamcVtzhuvpPqe3Y= @@ -1480,10 +1491,14 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.392 h1:O9BhkAY github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.392/go.mod h1:i7xMr7hiOKobK28YqZxkcPmPAThjxInKOQftIQ1J7nc= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sslpod v1.0.392/go.mod h1:h/84RSkOo7dgbGOAwYSV2WdWkUv2OQoVRjNfrJS6jUM= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.392/go.mod h1:NN8F2vmQ4hnA/iCq+/4ekfocQdbIlWvT4rNCjx+DmcI= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.617 h1:DoBtnZDFdt08o9it3r2aUxDr/G4y6mC56eUy9LrFmSU= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.617/go.mod h1:GQkgEwro7Qt/SDgrAqKi9EecbPoZyK4sgB/WdusRg70= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts v1.0.392/go.mod h1:kWzzUFykmDWPoh3t6mO3Cm0pNJr3P0DHpmfITVVsA+g= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/taf v1.0.392/go.mod h1:p/huA59BWTe2ICfslUzb9CmVkKS3d0kHzaPU1upcUj4= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.392/go.mod h1:4lW1UzRtbnhOqKDTTkn6Ur9eBtJyzcgpg4KnLxsp/RM= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.392/go.mod h1:khrPL4zu0yZ6nCvxmprL/exY5dX+aYLoq0Wf5ZA6zoQ= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.617 h1:BrucbQpntqo3dEZhYZv7ws72nKpAqZL2mQ9NPzCNxCE= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.617/go.mod h1:wKeLcYaZD7mtEG4muLepDHDMtkIAxZDpibfv89E0aXg= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tav v1.0.392/go.mod h1:mVONhjO15kJGkTN092oi4C9I92RdC9wE4mlc9q6kmt0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tbaas v1.0.392/go.mod h1:xf2aD/TKZhvw3FHqQw/p6Ye+KpknwV1ieBA75F1mt6w= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tbm v1.0.392/go.mod h1:wf8iEdOIPGM6csi0lGfqnB1j/SX8jr5liwUZwwt6oUc= @@ -1494,12 +1509,16 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcb v1.0.392/go.mod h1: github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcex v1.0.392/go.mod h1:LbBLo9ZxesFf7FgpGaDaOMUr3NbNhjrIzF6jG3mwq6k= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tci v1.0.392/go.mod h1:7JzdYwICHrF8Cz2MWyPw/yo5j9/n2BtqE909Z25VVdc= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.392/go.mod h1:VRJDKhxen3gaxn4EisibPAyjewSY3vFaYSsLXoh4bZ0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.611 h1:XHqQKRcbCKfA+qzp06HTrQVTNzC114OISMa8ah6E7sk= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.611/go.mod h1:EJ4/uJpXb7htIzdskmwouHG9e/Famp97bQFeI7ARK0w= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.392/go.mod h1:3AZguzwaPAwRyLTUQm3h1ROEnnwkgMg49a/myZhBl40= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcss v1.0.392/go.mod h1:ibYN8So3r1ScxmJtGxV8wTs0nGxKvih+IOq6GLNtWzU= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.392/go.mod h1:m21mWip509ME/nUwrA+n9rBLpBb8Bjuo/HkHuEojkZo= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdid v1.0.392/go.mod h1:Do7u7dYFlitjrrXXMcnLivCGKVXI+mIENqFmqT4V/fs= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.392/go.mod h1:LfFhQr0uPl2GrjE0r7XghDu0PUWCoGBilP9NooPmpog= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.392/go.mod h1:afUYlMwHkDmUle3ZGxz32+Q/cwyjFgMgaF62Q+qg6DU= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.604 h1:NBTNRBrxgogT+B15SQUMErJfKNQ7ZE6sXdJe4GXSpXw= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.604/go.mod h1:rbcqXAUjppNop1I1v6R/Bc5RnVtDKoErDm2S9/Jgm6g= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.392/go.mod h1:kHQx6ynDcmtj3hjL8HFn8f0VCa88y8j3CouKZAHrEiU= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/thpc v1.0.392/go.mod h1:ujCoikwjBD2UmfZspopyqjmEXfpcEma5b3vGxuWYCoU= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tia v1.0.392/go.mod h1:t3hDg8esQAI5He9+HHsaBMwPlUtXHLKL1oDZEmNL86g= @@ -1523,6 +1542,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ump v1.0.392/go.mod h1: github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vm v1.0.392/go.mod h1:OhyaYhAbA0D8t4KeW9c0apOwDw1Hqzol0eY4Ez81IOI= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vms v1.0.392/go.mod h1:PowsbqMUl5Rvy5LcO5aN8QTdI+9xAHxzDEpjMJ0tZ64= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.392/go.mod h1:sSLZPQ/C1k3HDBkNUpDxs5vWua7D7QRlBqYzWG+1FEA= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.606 h1:/J2aNBxn5DLz7z01fa0KtDjX5lAy2X+ktu9UWVNrAe8= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.606/go.mod h1:9AMknIcaJ57qHtxu1P6yr9DNvjYJIF9KkSMor/iFejg= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.392 h1:nx8MQ8yJ3srpfEAlKLQKtOsBCBc30QJ3Q0RsSOGSphQ= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.392/go.mod h1:IAl660UAxdUtp1rHUwbUwxFCVqwk61xAIRbBk6QtTy8= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.392/go.mod h1:BQ6k/+94Dyt6lL3c1hCmZ5ZL4mQfA99rc5KYlIbXlRc= diff --git a/providers/tencentcloud/pts.go b/providers/tencentcloud/pts.go new file mode 100644 index 000000000..ecac1f9d3 --- /dev/null +++ b/providers/tencentcloud/pts.go @@ -0,0 +1,91 @@ +// Copyright 2022 The Terraformer Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tencentcloud + +import ( + "github.com/GoogleCloudPlatform/terraformer/terraformutils" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + pts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts/v20210728" +) + +type PtsGenerator struct { + TencentCloudService +} + +func (g *PtsGenerator) InitResources() error { + args := g.GetArgs() + region := args["region"].(string) + credential := args["credential"].(common.Credential) + profile := NewTencentCloudClientProfile() + client, err := pts.NewClient(&credential, region, profile) + client.WithHttpTransport(&LogRoundTripper{ + Verbose: g.Verbose, + }) + if err != nil { + return err + } + + if err := g.DescribeProjects(client); err != nil { + return err + } + + return nil +} +func (g *PtsGenerator) DescribeProjects(client *pts.Client) error { + request := pts.NewDescribeProjectsRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_pts_project") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + request.ProjectIds = append(request.ProjectIds, &filters[i]) + } + + var offset int64 = 0 + var limit int64 = 50 + allInstances := make([]*pts.Project, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeProjects(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.ProjectSet...) + if len(response.Response.ProjectSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.ProjectId, + *instance.ProjectId+"_"+*instance.ProjectId, + "tencentcloud_pts_project", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} diff --git a/providers/tencentcloud/ssm.go b/providers/tencentcloud/ssm.go new file mode 100644 index 000000000..3f4d00e69 --- /dev/null +++ b/providers/tencentcloud/ssm.go @@ -0,0 +1,127 @@ +// Copyright 2022 The Terraformer Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tencentcloud + +import ( + "github.com/GoogleCloudPlatform/terraformer/terraformutils" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + ssm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm/v20190923" +) + +type SsmGenerator struct { + TencentCloudService +} + +func (g *SsmGenerator) InitResources() error { + args := g.GetArgs() + region := args["region"].(string) + credential := args["credential"].(common.Credential) + profile := NewTencentCloudClientProfile() + client, err := ssm.NewClient(&credential, region, profile) + if err != nil { + return err + } + + if err := g.ListSecrets(client); err != nil { + return err + } + + return nil +} +func (g *SsmGenerator) ListSecrets(client *ssm.Client) error { + request := ssm.NewListSecretsRequest() + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*ssm.SecretMetadata, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.ListSecrets(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.SecretMetadatas...) + if len(response.Response.SecretMetadatas) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.SecretName, + *instance.SecretName+"_"+*instance.SecretName, + "tencentcloud_ssm_secret", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + if err := g.ListSecretVersionIds(client, *instance.SecretName, resource.ResourceName); err != nil { + return err + } + } + + return nil +} + +//func (g *SsmGenerator) ListSecretVersionIds(allInstances []*ssm.SecretMetadata, resourceName string) error { +// for _, instance := range allInstances { +// resource := terraformutils.NewResource( +// *instance.SecretName+"#"+"_", +// *instance.SecretName, +// "tencentcloud_ssm_secret_version", +// "tencentcloud", +// map[string]string{}, +// []string{}, +// map[string]interface{}{}, +// ) +// resource.AdditionalFields["secret_name"] = "${tencentcloud_ssm_secret." + resourceName + ".id}" +// g.Resources = append(g.Resources, resource) +// } +// +// return nil +//} + +func (g *SsmGenerator) ListSecretVersionIds(client *ssm.Client, secretName, resourceName string) error { + request := ssm.NewListSecretVersionIdsRequest() + + request.SecretName = &secretName + var allInstances []*ssm.VersionInfo + response, err := client.ListSecretVersionIds(request) + if err != nil { + return err + } + + allInstances = response.Response.Versions + for _, instance := range allInstances { + resource := terraformutils.NewResource( + secretName+"#"+*instance.VersionId, + secretName+"_"+*instance.VersionId, + "tencentcloud_ssm_secret_version", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + resource.AdditionalFields["secret_name"] = "${tencentcloud_ssm_secret." + resourceName + ".id}" + g.Resources = append(g.Resources, resource) + } + + return nil +} diff --git a/providers/tencentcloud/tat.go b/providers/tencentcloud/tat.go new file mode 100644 index 000000000..d8933654e --- /dev/null +++ b/providers/tencentcloud/tat.go @@ -0,0 +1,133 @@ +// Copyright 2022 The Terraformer Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tencentcloud + +import ( + "github.com/GoogleCloudPlatform/terraformer/terraformutils" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + tat "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat/v20201028" +) + +type TatGenerator struct { + TencentCloudService +} + +func (g *TatGenerator) InitResources() error { + args := g.GetArgs() + region := args["region"].(string) + credential := args["credential"].(common.Credential) + profile := NewTencentCloudClientProfile() + client, err := tat.NewClient(&credential, region, profile) + if err != nil { + return err + } + + if err := g.DescribeCommands(client); err != nil { + return err + } + + return nil +} +func (g *TatGenerator) DescribeCommands(client *tat.Client) error { + request := tat.NewDescribeCommandsRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_tat_command") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + request.CommandIds = append(request.CommandIds, &filters[i]) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*tat.Command, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeCommands(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.CommandSet...) + if len(response.Response.CommandSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.CommandId, + *instance.CommandId+"_"+*instance.CommandId, + "tencentcloud_tat_command", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + if err := g.DescribeInvokers(client, *instance.CommandId, resource.ResourceName); err != nil { + return err + } + } + + return nil +} +func (g *TatGenerator) DescribeInvokers(client *tat.Client, commandId, resourceName string) error { + request := tat.NewDescribeInvokersRequest() + request.Filters = []*tat.Filter{ + { + Name: String("command-id"), + Values: []*string{&commandId}, + }, + } + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*tat.Invoker, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeInvokers(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.InvokerSet...) + if len(response.Response.InvokerSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.InvokerId, + *instance.InvokerId+"_"+*instance.InvokerId, + "tencentcloud_tat_invoker", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + resource.AdditionalFields["command_id"] = "${tencentcloud_tat_command." + resourceName + ".id}" + g.Resources = append(g.Resources, resource) + } + + return nil +} diff --git a/providers/tencentcloud/tem.go b/providers/tencentcloud/tem.go new file mode 100644 index 000000000..e4412237e --- /dev/null +++ b/providers/tencentcloud/tem.go @@ -0,0 +1,123 @@ +// Copyright 2022 The Terraformer Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tencentcloud + +import ( + "github.com/GoogleCloudPlatform/terraformer/terraformutils" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + tem "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem/v20210701" +) + +type TemGenerator struct { + TencentCloudService +} + +func (g *TemGenerator) InitResources() error { + args := g.GetArgs() + region := args["region"].(string) + credential := args["credential"].(common.Credential) + profile := NewTencentCloudClientProfile() + client, err := tem.NewClient(&credential, region, profile) + client.WithHttpTransport(&LogRoundTripper{ + Verbose: g.Verbose, + }) + if err != nil { + return err + } + + if err := g.DescribeEnvironments(client); err != nil { + return err + } + + return nil +} +func (g *TemGenerator) DescribeEnvironments(client *tem.Client) error { + request := tem.NewDescribeEnvironmentsRequest() + + var offset int64 = 0 + var limit int64 = 50 + allInstances := make([]*tem.TemNamespaceInfo, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeEnvironments(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.Result.Records...) + if len(response.Response.Result.Records) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.EnvironmentId, + *instance.EnvironmentId+"_"+*instance.EnvironmentId, + "tencentcloud_tem_environment", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + if err := g.DescribeIngresses(client, *instance.EnvironmentId, resource.ResourceName); err != nil { + return err + } + } + + return nil +} +func (g *TemGenerator) DescribeIngresses(client *tem.Client, environmentId, resourceName string) error { + request := tem.NewDescribeIngressesRequest() + + request.EnvironmentId = &environmentId + request.ClusterNamespace = String("default") + var allInstances []*tem.IngressInfo + response, err := client.DescribeIngresses(request) + if err != nil { + return err + } + + allInstances = response.Response.Result + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.EnvironmentId+"#"+*instance.IngressName, + *instance.EnvironmentId+"_"+*instance.IngressName, + "tencentcloud_tem_gateway", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + + //ingress["environment_id"] = "${tencentcloud_tem_environment." + resourceName + ".id}" + g.Resources = append(g.Resources, resource) + } + + return nil +} + +//func (g *TemGenerator) PostConvertHook() error { +// for _, resource := range g.Resources { +// if resource.InstanceInfo.Type == "tencentcloud_tem_gateway" { +// resource.AdditionalFields["ingress.environment_id"] = "${tencentcloud_tem_environment." + resource.ResourceName + ".id}" +// } +// } +// +// return nil +//} diff --git a/providers/tencentcloud/tencentcloud_provider.go b/providers/tencentcloud/tencentcloud_provider.go index 49e7eda8f..c30743d73 100755 --- a/providers/tencentcloud/tencentcloud_provider.go +++ b/providers/tencentcloud/tencentcloud_provider.go @@ -111,6 +111,11 @@ func (p *TencentCloudProvider) GetSupportedService() map[string]terraformutils.S "route_table": &RouteTableGenerator{}, "nat_gateway": &NatGatewayGenerator{}, "acl": &ACLGenerator{}, + "tem": &TemGenerator{}, + "pts": &PtsGenerator{}, + "vod": &VodGenerator{}, + "tat": &TatGenerator{}, + "ssm": &SsmGenerator{}, } } @@ -189,6 +194,10 @@ func (p *TencentCloudProvider) GetResourceConnections() map[string]map[string][] "cbs": { "cvm": []string{"instance_id", "id"}, }, + "tem": { + "vpc": []string{"vpc_id", "id"}, + "subnet": []string{"subnet_id", "id"}, + }, } } diff --git a/providers/tencentcloud/tencentcloud_service.go b/providers/tencentcloud/tencentcloud_service.go index fe5e430e5..22f516b45 100755 --- a/providers/tencentcloud/tencentcloud_service.go +++ b/providers/tencentcloud/tencentcloud_service.go @@ -14,8 +14,113 @@ package tencentcloud -import "github.com/GoogleCloudPlatform/terraformer/terraformutils" +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "os" + "time" + + "github.com/GoogleCloudPlatform/terraformer/terraformutils" +) type TencentCloudService struct { //nolint terraformutils.Service } + +const RequestClient = "TENCENTCLOUD_API_REQUEST_CLIENT" + +var ReqClient = "Terraformer-latest" + +type LogRoundTripper struct { + Verbose bool +} + +func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Response, errRet error) { + var inBytes, outBytes []byte + var start = time.Now() + + if me.Verbose { + defer func() { me.log(inBytes, outBytes, errRet, start) }() + } + + bodyReader, errRet := request.GetBody() + if errRet != nil { + return + } + var headName = "X-TC-Action" + + if envReqClient := os.Getenv(RequestClient); envReqClient != "" { + ReqClient = envReqClient + } + + request.Header.Set("X-TC-RequestClient", ReqClient) + inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName])) + requestBody, errRet := ioutil.ReadAll(bodyReader) + if errRet != nil { + return + } + inBytes = append(inBytes, requestBody...) + + headName = "X-TC-Region" + appendMessage := []byte(fmt.Sprintf( + ", (host %+v, region:%+v)", + request.Header["Host"], + request.Header[headName], + )) + + inBytes = append(inBytes, appendMessage...) + + response, errRet = http.DefaultTransport.RoundTrip(request) + if errRet != nil { + return + } + outBytes, errRet = ioutil.ReadAll(response.Body) + if errRet != nil { + return + } + response.Body = ioutil.NopCloser(bytes.NewBuffer(outBytes)) + + return +} + +func (me *LogRoundTripper) log(in []byte, out []byte, err error, start time.Time) { + var buf bytes.Buffer + buf.WriteString("#########") + tag := "[DEBUG]" + if err != nil { + tag = "[CRITICAL]" + } + buf.WriteString(tag) + if len(in) > 0 { + buf.WriteString("tencentcloud-sdk-go: ") + buf.Write(in) + } + if len(out) > 0 { + buf.WriteString("; response:") + err := json.Compact(&buf, out) + if err != nil { + out := bytes.Replace(out, + []byte("\n"), + []byte(""), + -1) + out = bytes.Replace(out, + []byte(" "), + []byte(""), + -1) + buf.Write(out) + } + } + + if err != nil { + buf.WriteString("; error:") + buf.WriteString(err.Error()) + } + + costFormat := fmt.Sprintf(",cost %s", time.Since(start).String()) + buf.WriteString(costFormat) + + fmt.Println(buf.String()) +} diff --git a/providers/tencentcloud/utils.go b/providers/tencentcloud/utils.go new file mode 100644 index 000000000..19f50da43 --- /dev/null +++ b/providers/tencentcloud/utils.go @@ -0,0 +1,15 @@ +package tencentcloud + +func Bool(i bool) *bool { return &i } + +func String(i string) *string { return &i } + +func Int(i int) *int { return &i } + +func Uint(i uint) *uint { return &i } + +func Int64(i int64) *int64 { return &i } + +func Float64(i float64) *float64 { return &i } + +func Uint64(i uint64) *uint64 { return &i } \ No newline at end of file diff --git a/providers/tencentcloud/vod.go b/providers/tencentcloud/vod.go new file mode 100644 index 000000000..786224f0b --- /dev/null +++ b/providers/tencentcloud/vod.go @@ -0,0 +1,349 @@ +// Copyright 2022 The Terraformer Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tencentcloud + +import ( + "strconv" + + "github.com/GoogleCloudPlatform/terraformer/terraformutils" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + vod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717" +) + +type VodGenerator struct { + TencentCloudService +} + +func (g *VodGenerator) InitResources() error { + args := g.GetArgs() + region := args["region"].(string) + credential := args["credential"].(common.Credential) + profile := NewTencentCloudClientProfile() + client, err := vod.NewClient(&credential, region, profile) + client.WithHttpTransport(&LogRoundTripper{ + Verbose: g.Verbose, + }) + if err != nil { + return err + } + + if err := g.DescribeSubAppIds(client); err != nil { + return err + } + if err := g.DescribeImageSpriteTemplates(client); err != nil { + return err + } + if err := g.DescribeAdaptiveDynamicStreamingTemplates(client); err != nil { + return err + } + if err := g.DescribeSnapshotByTimeOffsetTemplates(client); err != nil { + return err + } + if err := g.DescribeProcedureTemplates(client); err != nil { + return err + } + if err := g.DescribeSuperPlayerConfigs(client); err != nil { + return err + } + + return nil +} + +func (g *VodGenerator) DescribeSubAppIds(client *vod.Client) error { + request := vod.NewDescribeSubAppIdsRequest() + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.SubAppIdInfo, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeSubAppIds(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.SubAppIdInfoSet...) + if len(response.Response.SubAppIdInfoSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + if *instance.Name == "主应用" && *instance.SubAppIdName == "PrimaryApplication" { + continue + } + resource := terraformutils.NewResource( + *instance.Name+"#"+strconv.FormatUint(*instance.SubAppId, 10), + *instance.Name+"_"+strconv.FormatUint(*instance.SubAppId, 10), + "tencentcloud_vod_sub_application", + "tencentcloud", + map[string]string{ + "status": *instance.Status, + }, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} +func (g *VodGenerator) DescribeImageSpriteTemplates(client *vod.Client) error { + request := vod.NewDescribeImageSpriteTemplatesRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_vod_image_sprite_template") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + definition, err := strconv.Atoi(filters[i]) + if err != nil { + return err + } + d := uint64(definition) + request.Definitions = append(request.Definitions, &d) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.ImageSpriteTemplate, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeImageSpriteTemplates(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.ImageSpriteTemplateSet...) + if len(response.Response.ImageSpriteTemplateSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + strconv.FormatUint(*instance.Definition, 10), + strconv.FormatUint(*instance.Definition, 10), + "tencentcloud_vod_image_sprite_template", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} +func (g *VodGenerator) DescribeAdaptiveDynamicStreamingTemplates(client *vod.Client) error { + request := vod.NewDescribeAdaptiveDynamicStreamingTemplatesRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_vod_adaptive_dynamic_streaming_template") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + definition, err := strconv.Atoi(filters[i]) + if err != nil { + return err + } + d := uint64(definition) + request.Definitions = append(request.Definitions, &d) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.AdaptiveDynamicStreamingTemplate, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeAdaptiveDynamicStreamingTemplates(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.AdaptiveDynamicStreamingTemplateSet...) + if len(response.Response.AdaptiveDynamicStreamingTemplateSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + strconv.FormatUint(*instance.Definition, 10), + strconv.FormatUint(*instance.Definition, 10), + "tencentcloud_vod_adaptive_dynamic_streaming_template", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} +func (g *VodGenerator) DescribeSnapshotByTimeOffsetTemplates(client *vod.Client) error { + request := vod.NewDescribeSnapshotByTimeOffsetTemplatesRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_vod_snapshot_by_time_offset_template") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + definition, err := strconv.Atoi(filters[i]) + if err != nil { + return err + } + d := uint64(definition) + request.Definitions = append(request.Definitions, &d) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.SnapshotByTimeOffsetTemplate, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeSnapshotByTimeOffsetTemplates(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.SnapshotByTimeOffsetTemplateSet...) + if len(response.Response.SnapshotByTimeOffsetTemplateSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + strconv.FormatUint(*instance.Definition, 10), + strconv.FormatUint(*instance.Definition, 10), + "tencentcloud_vod_snapshot_by_time_offset_template", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} +func (g *VodGenerator) DescribeProcedureTemplates(client *vod.Client) error { + request := vod.NewDescribeProcedureTemplatesRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_vod_procedure_template") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + request.Names = append(request.Names, &filters[i]) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.ProcedureTemplate, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeProcedureTemplates(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.ProcedureTemplateSet...) + if len(response.Response.ProcedureTemplateSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.Name, + *instance.Name, + "tencentcloud_vod_procedure_template", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +} +func (g *VodGenerator) DescribeSuperPlayerConfigs(client *vod.Client) error { + request := vod.NewDescribeSuperPlayerConfigsRequest() + filters := make([]string, 0) + for _, filter := range g.Filter { + if filter.FieldPath == "id" && filter.IsApplicable("tencentcloud_vod_super_player_config") { + filters = append(filters, filter.AcceptableValues...) + } + } + + for i := range filters { + request.Names = append(request.Names, &filters[i]) + } + + var offset uint64 = 0 + var limit uint64 = 50 + allInstances := make([]*vod.PlayerConfig, 0) + for { + request.Offset = &offset + request.Limit = &limit + response, err := client.DescribeSuperPlayerConfigs(request) + if err != nil { + return err + } + allInstances = append(allInstances, response.Response.PlayerConfigSet...) + if len(response.Response.PlayerConfigSet) < int(limit) { + break + } + + offset += limit + } + + for _, instance := range allInstances { + resource := terraformutils.NewResource( + *instance.Name, + *instance.Name, + "tencentcloud_vod_super_player_config", + "tencentcloud", + map[string]string{}, + []string{}, + map[string]interface{}{}, + ) + g.Resources = append(g.Resources, resource) + } + + return nil +}