Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
tamperMonkeyZQ committed Dec 25, 2023
2 parents 570b1ef + 4d838c4 commit e997935
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 65 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
## 1.19.23 (Unreleased)
## 1.19.22 (December 25, 2023)
## 1.19.25 (Unreleased)
## 1.19.24 (December 25, 2023)
NOTES:
- The nat gateway now supports the DNAT and SNAT eips.

## 1.19.23 (November 27, 2023)
NOTES:
- ADD SCS Security ip.

## 1.19.22 (November 24, 2023)
NOTES:
- The routing table now supports import.

## 1.19.21 (November 15, 2023)
NOTES:
- The routing table now supports the configuration of dedicated gateways, including single-line and multi-line routing.
Expand Down
1 change: 1 addition & 0 deletions baiducloud/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
BaiduCloudTestResourceTypeNameRdsSecurityIp = BaiduCloudTestResourceTypeName + "-" + "rds-security-ip"
BaiduCloudTestResourceTypeNameRouteRule = BaiduCloudTestResourceTypeName + "-" + "route-rule"
BaiduCloudTestResourceTypeNameScs = BaiduCloudTestResourceTypeName + "-" + "scs"
BaiduCloudTestResourceTypeNameScsSecurityIp = BaiduCloudTestResourceTypeName + "-" + "scs-security-ip"
BaiduCloudTestResourceTypeNameSecurityGroup = BaiduCloudTestResourceTypeName + "-" + "security-group"
BaiduCloudTestResourceTypeNameSecurityGroupRule = BaiduCloudTestResourceTypeName + "-" + "security-group-rule"
BaiduCloudTestResourceTypeNameSnapshot = BaiduCloudTestResourceTypeName + "-" + "snapshot"
Expand Down
98 changes: 98 additions & 0 deletions baiducloud/data_source_baiducloud_scs_security_ips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Use this data source to query SCS security ips.
Example Usage
```hcl
data "baiducloud_scs_security_ips" "default" {
instance_id = "scs-xxxxx"
}
output "security_ips" {
value = "${data.baiducloud_scs.default.security_ips}"
}
```
*/
package baiducloud

import (
"github.com/baidubce/bce-sdk-go/services/scs"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"github.com/terraform-providers/terraform-provider-baiducloud/baiducloud/connectivity"
)

func dataSourceBaiduCloudScsSecurityIps() *schema.Resource {
return &schema.Resource{
Read: dataSourceBaiduCloudScsSecurityIpsRead,

Schema: map[string]*schema.Schema{
"instance_id": {
Type: schema.TypeString,
Description: "ID of the instance",
Required: true,
ForceNew: true,
},
"security_ips": {
Type: schema.TypeList,
Description: "security_ips",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Type: schema.TypeString,
Description: "securityIp",
Computed: true,
},
},
},
},
},
}
}

func dataSourceBaiduCloudScsSecurityIpsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.BaiduClient)

instanceID := d.Get("instance_id").(string)
action := "Query SCS SecurityIp instanceID is " + instanceID

raw, err := client.WithScsClient(func(scsClient *scs.Client) (interface{}, error) {
return scsClient.GetSecurityIp(instanceID)
})

addDebug(action, raw)

if err != nil {
if NotFoundError(err) {
d.SetId("")
return nil
}
return WrapErrorf(err, DefaultErrorMsg, "baiducloud_scs_security_ips", action, BCESDKGoERROR)
}

securityIpsResult, _ := raw.(*scs.GetSecurityIpResult)
securityIps := make([]map[string]interface{}, 0)
for _, ip := range securityIpsResult.SecurityIps {
ipMap := make(map[string]interface{})
ipMap["ip"] = ip
securityIps = append(securityIps, ipMap)
}
addDebug(action, securityIps)

FilterDataSourceResult(d, &securityIps)

if err := d.Set("security_ips", securityIps); err != nil {
return WrapErrorf(err, DefaultErrorMsg, "baiducloud_scs_security_ips", action, BCESDKGoERROR)
}

d.SetId(resource.UniqueId())

if v, ok := d.GetOk("output_file"); ok && v.(string) != "" {
if err := writeToFile(v.(string), securityIps); err != nil {
return WrapErrorf(err, DefaultErrorMsg, "baiducloud_scs_security_ips", action, BCESDKGoERROR)
}
}
return nil
}
66 changes: 66 additions & 0 deletions baiducloud/data_source_baiducloud_scs_security_ips_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package baiducloud

import (
"fmt"
"testing"

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

const (
testAccScsSecurityIpDataSourceName = "data.baiducloud_scs_security_ips.default"
testAccScsSecurityIpDataSourceAttrKeyPrefix = "security_ips.0."
)

//lintignore:AT003
func TestAccBaiduCloudScsSecurityIpDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccScsSecurityIpDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckBaiduCloudDataSourceId(testAccScsSecurityIpDataSourceName),
resource.TestCheckResourceAttrSet(testAccScsSecurityIpDataSourceName, testAccScsSecurityIpDataSourceAttrKeyPrefix+"ip"),
),
},
},
})
}

func testAccScsSecurityIpDataSourceConfig() string {
return fmt.Sprintf(`
data "baiducloud_scs_security_ips" "default" {
instance_id = "scs-bj-hzsywuljybfy"
}
`)
}

func testAccScsSecurityIpFullConfig() string {
return fmt.Sprintf(`
resource "baiducloud_scs" "default" {
instance_name = "scs-test"
billing = {
payment_timing = "Postpaid"
}
purchase_count = 1
port = 6379
engine_version = "3.2"
node_type = "cache.n1.micro"
cluster_type = "master_slave"
replication_num = 1
shard_num = 1
proxy_num = 0
}
data "baiducloud_scs_security_ips" "default" {
instance_id = baiducloud_scs.default.id
}
`)
}
2 changes: 2 additions & 0 deletions baiducloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func Provider() terraform.ResourceProvider {
"baiducloud_cfc_function": dataSourceBaiduCloudCFCFunction(),
"baiducloud_scs_specs": dataSourceBaiduCloudScsSpecs(),
"baiducloud_scss": dataSourceBaiduCloudScss(),
"baiducloud_scs_security_ips": dataSourceBaiduCloudScsSecurityIps(),
"baiducloud_cce_versions": dataSourceBaiduCloudCceKubernetesVersion(),
"baiducloud_cce_container_net": dataSourceBaiduCloudCceContainerNet(),
"baiducloud_cce_cluster_nodes": dataSourceBaiduCloudCCEClusterNodes(),
Expand Down Expand Up @@ -271,6 +272,7 @@ func Provider() terraform.ResourceProvider {
"baiducloud_cfc_version": resourceBaiduCloudCFCVersion(),
"baiducloud_cfc_trigger": resourceBaiduCloudCFCTrigger(),
"baiducloud_scs": resourceBaiduCloudScs(),
"baiducloud_scs_security_ip": resourceBaiduCloudScsSecurityIp(),
"baiducloud_cce_cluster": resourceBaiduCloudCCECluster(),
"baiducloud_ccev2_cluster": resourceBaiduCloudCCEv2Cluster(),
"baiducloud_ccev2_instance": resourceBaiduCloudCCEv2Instance(),
Expand Down
74 changes: 41 additions & 33 deletions baiducloud/resource_baiducloud_route_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resource "baiducloud_route_rule" "default" {
package baiducloud

import (
"strings"
"time"

"github.com/baidubce/bce-sdk-go/bce"
Expand Down Expand Up @@ -72,36 +73,39 @@ func resourceBaiduCloudRouteRule() *schema.Resource {
Computed: true,
ForceNew: true,
},
"next_hop_list": {
Type: schema.TypeList,
Description: "Create a multi-path route based on the next hop information. This field is required when creating a multi-path route.",
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"next_hop_id": {
Type: schema.TypeString,
Description: "Next-hop ID.",
Required: true,
ForceNew: true,
},
"next_hop_type": {
Type: schema.TypeString,
Description: "Routing type. Currently only the dedicated gateway type dcGateway is supported.",
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"dcGateway"}, false),
},
"path_type": {
Type: schema.TypeString,
Description: "Multi-line mode. The load balancing value is ecmp; the main backup mode value is ha:active, ha:standby, which represent the main and backup routes respectively.",
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"ecmp", "ha:active", "ha:standby"}, false),
},
},
},
},
/**
* todo 目前OpenAPI的多线路由只支持创建,查询和更新都不支持,所以暂时不开放,待API完善后开放
*/
//"next_hop_list": {
// Type: schema.TypeList,
// Description: "Create a multi-path route based on the next hop information. This field is required when creating a multi-path route.",
// Optional: true,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "next_hop_id": {
// Type: schema.TypeString,
// Description: "Next-hop ID.",
// Required: true,
// ForceNew: true,
// },
// "next_hop_type": {
// Type: schema.TypeString,
// Description: "Routing type. Currently only the dedicated gateway type dcGateway is supported.",
// Required: true,
// ForceNew: true,
// ValidateFunc: validation.StringInSlice([]string{"dcGateway"}, false),
// },
// "path_type": {
// Type: schema.TypeString,
// Description: "Multi-line mode. The load balancing value is ecmp; the main backup mode value is ha:active, ha:standby, which represent the main and backup routes respectively.",
// Required: true,
// ForceNew: true,
// ValidateFunc: validation.StringInSlice([]string{"ecmp", "ha:active", "ha:standby"}, false),
// },
// },
// },
//},
"next_hop_type": {
Type: schema.TypeString,
Description: "Type of the next hop, available values are custom, vpn, nat and dcGateway.",
Expand Down Expand Up @@ -150,11 +154,15 @@ func resourceBaiduCloudRouteRuleCreate(d *schema.ResourceData, meta interface{})
func resourceBaiduCloudRouteRuleRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.BaiduClient)

routeRuleId := d.Id()
idParts := strings.Split(d.Id(), ":")
routeRuleId := idParts[0]
action := "Query Route Rule " + routeRuleId

routeTableID := ""
if v, ok := d.GetOk("route_table_id"); ok {
if len(idParts) > 1 {
routeTableID = idParts[1]
d.SetId(idParts[0])
} else if v, ok := d.GetOk("route_table_id"); ok {
routeTableID = v.(string)
}
raw, err := client.WithVpcClient(func(vpcClient *vpc.Client) (i interface{}, e error) {
Expand All @@ -170,6 +178,7 @@ func resourceBaiduCloudRouteRuleRead(d *schema.ResourceData, meta interface{}) e
}

result, _ := raw.(*vpc.GetRouteTableResult)
d.SetId(routeRuleId)
for _, rule := range result.RouteRules {
if rule.RouteRuleId == routeRuleId {
d.Set("route_table_id", rule.RouteTableId)
Expand All @@ -178,7 +187,6 @@ func resourceBaiduCloudRouteRuleRead(d *schema.ResourceData, meta interface{}) e
d.Set("next_hop_id", rule.NexthopId)
d.Set("next_hop_type", rule.NexthopType)
d.Set("description", rule.Description)

return nil
}
}
Expand Down
Loading

0 comments on commit e997935

Please sign in to comment.