Skip to content

Commit

Permalink
add enterprise_project_id to dcs, nat_gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Oct 21, 2020
1 parent 686528a commit 2d99ba1
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 93 deletions.
2 changes: 2 additions & 0 deletions docs/resources/dcs_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ The following arguments are supported:
* `backup_at` - (Optional) Day in a week on which backup starts. Range: 1–7. Where: 1
indicates Monday; 7 indicates Sunday. Changing this creates a new instance.

* `enterprise_project_id` - (Optional) The enterprise project id of the dcs instance. Changing this creates a new instance.

The `whitelists` block supports:

* `group_name` - (Required) Specifies the name of IP address group.
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/nat_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ The following arguments are supported:
* `internal_network_id` - (Optional) ID of the network this nat gateway connects to.
Changing this creates a new nat gateway.

* `enterprise_project_id` - (Optional) The enterprise project id of the nat gateway.
Changing this creates a new nat gateway.

## Attributes Reference

The following attributes are exported:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20201019092827-0254ff170b2e
github.com/huaweicloud/golangsdk v0.0.0-20201021110706-4cb6032799d8
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20201010022156-88a65d817494 h1:3nOQxuXHUIYRS94unYux1/K+l5p1w/OhcqNVGJ3ejAU=
github.com/huaweicloud/golangsdk v0.0.0-20201010022156-88a65d817494/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201013113019-d00b298c3cdd h1:98+a/BpLn8AJBvFEKZIxAt4TnyWcgfOF02PQQoj9+Js=
github.com/huaweicloud/golangsdk v0.0.0-20201013113019-d00b298c3cdd/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201019092827-0254ff170b2e h1:3/OcFZHyBNfPlLxv8BiCP3b6rkzhfIQWU2TmwBEmb7g=
github.com/huaweicloud/golangsdk v0.0.0-20201019092827-0254ff170b2e/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201021110706-4cb6032799d8 h1:x028T/6qFLr/WXVVqHShpnIgFz9U8NmfjZVag3zvFF8=
github.com/huaweicloud/golangsdk v0.0.0-20201021110706-4cb6032799d8/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
5 changes: 2 additions & 3 deletions huaweicloud/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ var allServiceCatalog = map[string]ServiceCatalog{
WithOutProjectID: true,
},
"natv2": ServiceCatalog{
Name: "nat",
Version: "v2.0",
WithOutProjectID: true,
Name: "nat",
Version: "v2",
},
"elb": ServiceCatalog{
Name: "elb",
Expand Down
48 changes: 32 additions & 16 deletions huaweicloud/resource_huaweicloud_dcs_instance_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ func resourceDcsInstanceV1() *schema.Resource {
},
},
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"enterprise_project_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"order_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -293,22 +305,24 @@ func resourceDcsInstancesV1Create(d *schema.ResourceData, meta interface{}) erro
no_password_access = "false"
}
createOpts := &instances.CreateOps{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Engine: d.Get("engine").(string),
EngineVersion: d.Get("engine_version").(string),
Capacity: d.Get("capacity").(float64),
NoPasswordAccess: no_password_access,
Password: d.Get("password").(string),
AccessUser: d.Get("access_user").(string),
VPCID: d.Get("vpc_id").(string),
SecurityGroupID: d.Get("security_group_id").(string),
SubnetID: d.Get("subnet_id").(string),
AvailableZones: getAllAvailableZones(d),
ProductID: d.Get("product_id").(string),
InstanceBackupPolicy: getInstanceBackupPolicy(d),
MaintainBegin: d.Get("maintain_begin").(string),
MaintainEnd: d.Get("maintain_end").(string),
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Engine: d.Get("engine").(string),
EngineVersion: d.Get("engine_version").(string),
Capacity: d.Get("capacity").(float64),
NoPasswordAccess: no_password_access,
Password: d.Get("password").(string),
AccessUser: d.Get("access_user").(string),
VPCID: d.Get("vpc_id").(string),
SecurityGroupID: d.Get("security_group_id").(string),
SubnetID: d.Get("subnet_id").(string),
AvailableZones: getAllAvailableZones(d),
ProductID: d.Get("product_id").(string),
InstanceBackupPolicy: getInstanceBackupPolicy(d),
MaintainBegin: d.Get("maintain_begin").(string),
MaintainEnd: d.Get("maintain_end").(string),
EnterpriseProjectID: GetEnterpriseProjectID(d, config),
EnterpriseProjectName: d.Get("enterprise_project_name").(string),
}

log.Printf("[DEBUG] Create Options: %#v", createOpts)
Expand Down Expand Up @@ -394,6 +408,8 @@ func resourceDcsInstancesV1Read(d *schema.ResourceData, meta interface{}) error
d.Set("maintain_begin", v.MaintainBegin)
d.Set("maintain_end", v.MaintainEnd)
d.Set("access_user", v.AccessUser)
d.Set("enterprise_project_id", v.EnterpriseProjectID)
d.Set("enterprise_project_name", v.EnterpriseProjectName)

// set capacity by Capacity and CapacityMinor
var capacity float64 = float64(v.Capacity)
Expand Down
54 changes: 54 additions & 0 deletions huaweicloud/resource_huaweicloud_dcs_instance_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ func TestAccDcsInstancesV1_basic(t *testing.T) {
})
}

func TestAccDcsInstancesV1_withEpsId(t *testing.T) {
var instance instances.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))
resourceName := "huaweicloud_dcs_instance.instance_1"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEpsID(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDcsV1InstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccDcsV1Instance_epsId(instanceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDcsV1InstanceExists(resourceName, instance),
resource.TestCheckResourceAttr(resourceName, "name", instanceName),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID),
),
},
},
})
}

func TestAccDcsInstancesV1_whitelists(t *testing.T) {
var instance instances.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))
Expand Down Expand Up @@ -166,6 +188,38 @@ func testAccDcsV1Instance_basic(instanceName string) string {
`, OS_AVAILABILITY_ZONE, instanceName, OS_VPC_ID, OS_NETWORK_ID)
}

func testAccDcsV1Instance_epsId(instanceName string) string {
return fmt.Sprintf(`
resource "huaweicloud_networking_secgroup" "secgroup_1" {
name = "secgroup_1"
description = "secgroup_1"
}
data "huaweicloud_dcs_az" "az_1" {
code = "%s"
}
resource "huaweicloud_dcs_instance" "instance_1" {
name = "%s"
engine_version = "3.0"
password = "Huawei_test"
engine = "Redis"
capacity = 2
vpc_id = "%s"
security_group_id = huaweicloud_networking_secgroup.secgroup_1.id
subnet_id = "%s"
available_zones = [data.huaweicloud_dcs_az.az_1.id]
product_id = "dcs.master_standby-h"
save_days = 1
backup_type = "manual"
begin_at = "00:00-01:00"
period_type = "weekly"
backup_at = [1]
depends_on = ["huaweicloud_networking_secgroup.secgroup_1"]
enterprise_project_id = "%s"
}
`, OS_AVAILABILITY_ZONE, instanceName, OS_VPC_ID, OS_NETWORK_ID, OS_ENTERPRISE_PROJECT_ID)
}

func testAccDcsV1Instance_tiny(instanceName string) string {
return fmt.Sprintf(`
data "huaweicloud_dcs_az" "az_1" {
Expand Down
20 changes: 14 additions & 6 deletions huaweicloud/resource_huaweicloud_nat_gateway_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func resourceNatGatewayV2() *schema.Resource {
Required: true,
ForceNew: true,
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
},
}
}
Expand All @@ -76,12 +82,13 @@ func resourceNatGatewayV2Create(d *schema.ResourceData, meta interface{}) error
}

createOpts := &natgateways.CreateOpts{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Spec: d.Get("spec").(string),
TenantID: d.Get("tenant_id").(string),
RouterID: d.Get("router_id").(string),
InternalNetworkID: d.Get("internal_network_id").(string),
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Spec: d.Get("spec").(string),
TenantID: d.Get("tenant_id").(string),
RouterID: d.Get("router_id").(string),
InternalNetworkID: d.Get("internal_network_id").(string),
EnterpriseProjectID: GetEnterpriseProjectID(d, config),
}

log.Printf("[DEBUG] Create Options: %#v", createOpts)
Expand Down Expand Up @@ -130,6 +137,7 @@ func resourceNatGatewayV2Read(d *schema.ResourceData, meta interface{}) error {
d.Set("tenant_id", natGateway.TenantID)

d.Set("region", GetRegion(d, config))
d.Set("enterprise_project_id", natGateway.EnterpriseProjectID)

return nil
}
Expand Down
45 changes: 45 additions & 0 deletions huaweicloud/resource_huaweicloud_nat_gateway_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

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

Expand Down Expand Up @@ -45,6 +46,25 @@ func TestAccNatGateway_basic(t *testing.T) {
})
}

func TestAccNatGateway_withEpsId(t *testing.T) {
natgateway := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckNat(t); testAccPreCheckEpsID(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNatV2GatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccNatV2Gateway_epsId(natgateway),
Check: resource.ComposeTestCheckFunc(
testAccCheckNatV2GatewayExists("huaweicloud_nat_gateway.nat_1"),
resource.TestCheckResourceAttr("huaweicloud_nat_gateway.nat_1", "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID),
),
},
},
})
}

func testAccCheckNatV2GatewayDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
natClient, err := config.natV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -128,6 +148,31 @@ resource "huaweicloud_nat_gateway_v2" "nat_1" {
}
`

func testAccNatV2Gateway_epsId(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_vpc" "vpc_1" {
name = "%s"
cidr = "192.168.0.0/16"
}
resource "huaweicloud_vpc_subnet" "subnet_1" {
name = "%s"
cidr = "192.168.199.0/24"
gateway_ip = "192.168.199.1"
vpc_id = huaweicloud_vpc.vpc_1.id
}
resource "huaweicloud_nat_gateway" "nat_1" {
name = "%s"
description = "test for terraform"
spec = "1"
internal_network_id = huaweicloud_vpc_subnet.subnet_1.id
router_id = huaweicloud_vpc.vpc_1.id
enterprise_project_id = "%s"
}
`, name, name, name, OS_ENTERPRISE_PROJECT_ID)
}

const testAccNatV2Gateway_update = `
resource "huaweicloud_networking_router_v2" "router_1" {
name = "router_1"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d99ba1

Please sign in to comment.