-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(NAT): Synchronized NAT resource, unit test and document. #1091
Closed
liwanting0517
wants to merge
1
commit into
FlexibleEngineCloud:master
from
liwanting0517:lwt_dev_nat_snat_rule_v2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
flexibleengine/acceptance/resource_flexibleengine_nat_snat_rule_v2_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/chnsz/golangsdk/openstack/nat/v2/snats" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func getPublicSnatRuleResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := cfg.NatGatewayClient(OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating NAT v2 client: %s", err) | ||
} | ||
|
||
return snats.Get(client, state.Primary.ID) | ||
} | ||
|
||
func TestAccPublicSnatRule_basic(t *testing.T) { | ||
var ( | ||
obj snats.Rule | ||
|
||
rName = "flexibleengine_nat_snat_rule_v2.test" | ||
name = acceptance.RandomAccResourceNameWithDash() | ||
) | ||
|
||
rc := acceptance.InitResourceCheck( | ||
rName, | ||
&obj, | ||
getPublicSnatRuleResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
ProviderFactories: TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccPublicSnatRule_basic_step_1(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrPair(rName, "nat_gateway_id", "flexibleengine_nat_gateway_v2.test", "id"), | ||
resource.TestCheckResourceAttrPair(rName, "subnet_id", "flexibleengine_vpc_subnet_v1.test", "id"), | ||
resource.TestCheckResourceAttrPair(rName, "floating_ip_id", "flexibleengine_vpc_eip.test.0", "id"), | ||
resource.TestCheckResourceAttr(rName, "description", "Created by acc test"), | ||
resource.TestCheckResourceAttr(rName, "status", "ACTIVE"), | ||
), | ||
}, | ||
{ | ||
Config: testAccPublicSnatRule_basic_step_2(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrPair(rName, "nat_gateway_id", "flexibleengine_nat_gateway_v2.test", "id"), | ||
resource.TestCheckResourceAttr(rName, "description", ""), | ||
resource.TestCheckResourceAttr(rName, "status", "ACTIVE"), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccPublicSnatRule_base(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "flexibleengine_vpc_eip" "test" { | ||
count = 2 | ||
|
||
publicip { | ||
type = "5_bgp" | ||
} | ||
|
||
bandwidth { | ||
name = format("%[2]s-%%d", count.index) | ||
size = 5 | ||
share_type = "PER" | ||
charge_mode = "traffic" | ||
} | ||
} | ||
|
||
resource "flexibleengine_compute_instance_v2" "test" { | ||
name = "instance_1" | ||
security_groups = ["default"] | ||
image_id = data.flexibleengine_images_image.test.id | ||
flavor_id = data.flexibleengine_compute_flavors_v2.test.flavors[0] | ||
availability_zone = data.flexibleengine_availability_zones.test.names[0] | ||
metadata = { | ||
foo = "bar" | ||
} | ||
network { | ||
uuid = flexibleengine_vpc_subnet_v1.test.id | ||
} | ||
tags = { | ||
key1 = "value1" | ||
key2 = "value.key" | ||
} | ||
} | ||
|
||
resource "flexibleengine_nat_gateway_v2" "test" { | ||
name = "%[2]s" | ||
description = "test for terraform" | ||
spec = "2" | ||
vpc_id = flexibleengine_vpc_v1.test.id | ||
subnet_id = flexibleengine_vpc_subnet_v1.test.id | ||
} | ||
`, testBaseComputeResources(name), name) | ||
} | ||
|
||
func testAccPublicSnatRule_basic_step_1(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "flexibleengine_nat_snat_rule_v2" "test" { | ||
nat_gateway_id = flexibleengine_nat_gateway_v2.test.id | ||
subnet_id = flexibleengine_vpc_subnet_v1.test.id | ||
floating_ip_id = flexibleengine_vpc_eip.test[0].id | ||
description = "Created by acc test" | ||
} | ||
`, testAccPublicSnatRule_base(name)) | ||
} | ||
|
||
func testAccPublicSnatRule_basic_step_2(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
resource "flexibleengine_nat_snat_rule_v2" "test" { | ||
nat_gateway_id = flexibleengine_nat_gateway_v2.test.id | ||
subnet_id = flexibleengine_vpc_subnet_v1.test.id | ||
floating_ip_id = join(",", flexibleengine_vpc_eip.test[*].id) | ||
} | ||
`, testAccPublicSnatRule_base(name)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep it as is.
page_title
is used for other platforms.