Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changelog/1726.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:new-data-source
tencentcloud_api_gateway_api_docs
```

```release-note:new-resource
tencentcloud_api_gateway_api_doc
```

```release-note:new-data-source
tencentcloud_api_gateway_api_apps
```

```release-note:new-resource
tencentcloud_api_gateway_api_app
```

```release-note:enhancement
resource/tencentcloud_api_gateway_custom_domain: support add `is_forced_https` params
```
7 changes: 7 additions & 0 deletions examples/tencentcloud-api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ resource "tencentcloud_api_gateway_strategy_attachment" "test"{
bind_api_id = tencentcloud_api_gateway_api.api.id
}

resource "tencentcloud_api_gateway_api_doc" "my_api_doc" {
api_doc_name = "create_doc_test"
service_id = tencentcloud_api_gateway_service_release.service.service_id
environment = "release"
api_ids = [tencentcloud_api_gateway_api.api.id]
}

data "tencentcloud_api_gateway_api_keys" "name" {
secret_name = tencentcloud_api_gateway_api_key.test.secret_name
}
Expand Down
170 changes: 170 additions & 0 deletions tencentcloud/data_source_tc_api_gateway_api_apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
Use this data source to query list information of api_gateway api_app

Example Usage

```hcl
data "tencentcloud_api_gateway_api_apps" "test" {
api_app_id = ["app-rj8t6zx3"]
api_app_name = ["app_test"]
}
```
*/
package tencentcloud

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudAPIGatewayAPIApps() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudAPIGatewayAPIAppsRead,
Schema: map[string]*schema.Schema{
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},

"api_app_id": {
Type: schema.TypeString,
Optional: true,
Description: "Api app ID.",
},

"api_app_name": {
Type: schema.TypeString,
Optional: true,
Description: "Api app name.",
},

"api_app_list": {
Type: schema.TypeList,
Computed: true,
Description: "List of ApiApp.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_app_id": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp ID.",
},
"api_app_name": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp Name.",
},
"api_app_key": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp key.",
},
"api_app_secret": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp secret.",
},
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp create time.",
},
"modified_time": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp modified time.",
},
"api_app_desc": {
Type: schema.TypeString,
Computed: true,
Description: "ApiApp description.",
},
},
},
},
},
}
}

func dataSourceTencentCloudAPIGatewayAPIAppsRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_api_gateway_api_apps.read")()
defer inconsistentCheck(d, meta)()

var (
logId = getLogId(contextNil)
ctx = context.WithValue(context.TODO(), logIdKey, logId)
apiGatewayService = APIGatewayService{client: meta.(*TencentCloudClient).apiV3Conn}
apiAppId, apiAppName string
apiApps []*apigateway.ApiAppInfo
)

if v, ok := d.GetOk("api_app_id"); ok {
apiAppId = v.(string)
}

if v, ok := d.GetOk("api_app_name"); ok {
apiAppName = v.(string)
}

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := apiGatewayService.DescribeApiAppList(ctx, apiAppId, apiAppName)
if e != nil {
return retryError(e)
}
apiApps = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s read api_gateway apiApps failed, reason:%+v", logId, err)
return err
}

apiAppList := []interface{}{}
ids := make([]string, 0, len(apiApps))
if apiApps != nil {
for _, item := range apiApps {
docMap := map[string]interface{}{}
if item.ApiAppId != nil {
docMap["api_app_id"] = item.ApiAppId
}
if item.ApiAppName != nil {
docMap["api_app_name"] = item.ApiAppName
}
if item.ApiAppKey != nil {
docMap["api_app_key"] = item.ApiAppKey
}
if item.ApiAppSecret != nil {
docMap["api_app_secret"] = item.ApiAppSecret
}
if item.CreatedTime != nil {
docMap["created_time"] = item.CreatedTime
}
if item.ModifiedTime != nil {
docMap["modified_time"] = item.ModifiedTime
}
if item.ApiAppDesc != nil {
docMap["api_app_desc"] = item.ApiAppDesc
}
apiAppList = append(apiAppList, docMap)
ids = append(ids, *item.ApiAppId)
}
_ = d.Set("api_app_list", apiAppList)
}

d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), apiAppList); e != nil {
return e
}
}

return nil
}
48 changes: 48 additions & 0 deletions tencentcloud/data_source_tc_api_gateway_api_apps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

var testAPIGatewayAPIAppsResourceName = "data.tencentcloud_api_gateway_api_apps"

// go test -i; go test -test.run TestAccTencentAPIGatewayAPIAppsDataSource_basic -v
func TestAccTencentAPIGatewayAPIAppsDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAPIGatewayAPIAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccTestAccTencentAPIGatewayAPIApps(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAPIGatewayAPIAppExists(testAPIGatewayAPIAppResourceName+".test"),
resource.TestCheckResourceAttr(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.#", "1"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_id"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_name"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_key"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_secret"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.created_time"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.modified_time"),
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_desc"),
),
},
},
})
}

func testAccTestAccTencentAPIGatewayAPIApps() string {
return `
resource "tencentcloud_api_gateway_api_app" "test" {
api_app_name = "app_test1"
api_app_desc = "create app desc"
}

data "tencentcloud_api_gateway_api_apps" "test" {
api_app_id = tencentcloud_api_gateway_api_app.test.id
}
`
}
114 changes: 114 additions & 0 deletions tencentcloud/data_source_tc_api_gateway_api_docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Use this data source to query list information of api_gateway api_doc
Example Usage
```hcl
data "tencentcloud_api_gateway_api_docs" "my_api_doc" {
}
```
*/
package tencentcloud

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudAPIGatewayAPIDocs() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudAPIGatewayAPIDocsRead,
Schema: map[string]*schema.Schema{
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},

"api_doc_list": {
Type: schema.TypeList,
Computed: true,
Description: "List of ApiDocs.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_doc_id": {
Type: schema.TypeString,
Computed: true,
Description: "Api Doc ID.",
},
"api_doc_name": {
Type: schema.TypeString,
Computed: true,
Description: "Api Doc Name.",
},
"api_doc_status": {
Type: schema.TypeString,
Computed: true,
Description: "Api Doc Status.",
},
},
},
},
},
}
}

func dataSourceTencentCloudAPIGatewayAPIDocsRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_api_gateway_api_docs.read")()
defer inconsistentCheck(d, meta)()

var (
logId = getLogId(contextNil)
ctx = context.WithValue(context.TODO(), logIdKey, logId)
apiGatewayService = APIGatewayService{client: meta.(*TencentCloudClient).apiV3Conn}
apiDoc []*apigateway.APIDoc
)

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
results, e := apiGatewayService.DescribeApiDocList(ctx)
if e != nil {
return retryError(e)
}

apiDoc = results
return nil
})

if err != nil {
log.Printf("[CRITAL]%s read api_gateway apiDocs failed, reason:%+v", logId, err)
return err
}

apiDocList := []interface{}{}
ids := make([]string, 0, len(apiDoc))
if apiDoc != nil {
for _, item := range apiDoc {
docMap := map[string]interface{}{}
if item.ApiDocId != nil {
docMap["api_doc_id"] = item.ApiDocId
}
if item.ApiDocName != nil {
docMap["api_doc_name"] = item.ApiDocName
}
if item.ApiDocStatus != nil {
docMap["api_doc_status"] = item.ApiDocStatus
}
apiDocList = append(apiDocList, docMap)
ids = append(ids, *item.ApiDocId)
}
_ = d.Set("api_doc_list", apiDocList)
}

d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), apiDocList); e != nil {
return e
}
}

return nil
}
Loading