Skip to content

Commit

Permalink
Merge pull request #161 from volcengine/Feat/ecs
Browse files Browse the repository at this point in the history
Feat/ecs
  • Loading branch information
msq177 authored Apr 3, 2024
2 parents cbd3ce6 + d845544 commit 523b01e
Show file tree
Hide file tree
Showing 111 changed files with 5,876 additions and 496 deletions.
21 changes: 14 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
OS=$1
ARCH=$2

NAME="terraform-provider-volcengine"
set -ea

Expand All @@ -8,15 +10,20 @@ then
OS="darwin"
fi

CGO_ENABLED=0 GOOS=$OS GOARCH=amd64 go build -o $NAME
rm -f $GOPATH/bin/$NAME
cp $NAME $GOPATH/bin/
if [ "$ARCH" == "" ]
then
ARCH="amd64"
fi

CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -o $NAME
# rm -f $GOPATH/bin/$NAME
# cp $NAME $GOPATH/bin/
# 如果terraform版本高于或者等于0.13
# 需要执行如下三条指令 来映射CLI到本地路径
# 如果小于此版本可以不做这三个操作
# shellcheck disable=SC2154
#mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_amd64/
#rm -f ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_amd64/"$NAME"_v0.0.1
#cp $NAME ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_amd64/"$NAME"_v0.0.1
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_"$ARCH"/
rm -f ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_"$ARCH"/"$NAME"_v0.0.1
cp $NAME ~/.terraform.d/plugins/registry.terraform.io/hashicorp/volcengine/0.0.1/"$OS"_"$ARCH"/"$NAME"_v0.0.1

rm -f $NAME
rm -f $NAME
4 changes: 4 additions & 0 deletions common/common_volcengine_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ func ResourceFlowLimitExceededError(err error) bool {
func UnsubscribeProductError(err error) bool {
return strings.Contains(err.Error(), "The product code is inconsistent with the instance product")
}

func UnsubscribeProductConflictError(err error) bool {
return strings.Contains(err.Error(), "RequestConflict")
}
2 changes: 1 addition & 1 deletion common/common_volcengine_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func FilterSystemTags(tags []interface{}) []interface{} {
}

func tagIgnored(tagKey string, tagValue interface{}) bool {
filter := []string{"^volc:"}
filter := []string{"^volc:", "^sys:"}
for _, v := range filter {
ok, _ := regexp.MatchString(v, tagKey)
if ok {
Expand Down
4 changes: 4 additions & 0 deletions common/common_volcengine_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func Test_FilterSystemTags(t *testing.T) {
"Key": "volc:ecs:linkedresource",
"Value": "trn:ecs:cn-beijing:222222",
},
map[string]interface{}{
"Key": "sys:ecs:linkedresource",
"Value": "trn:ecs:cn-beijing:222222",
},
}

res := FilterSystemTags(tags)
Expand Down
6 changes: 6 additions & 0 deletions common/common_volcengine_unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func (u *UnsubscribeService) UnsubscribeInstance(info *UnsubscribeInfo) []Callba
return nil
}
return resource.RetryableError(callErr)
} else if UnsubscribeProductConflictError(baseErr) {
_, callErr := call.ExecuteCall(d, client, call)
if callErr == nil {
return nil
}
return resource.RetryableError(callErr)
} else {
return resource.NonRetryableError(baseErr)
}
Expand Down
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.140"
TerraformProviderVersion = "0.0.141"
)
26 changes: 12 additions & 14 deletions example/bandwidthPackage/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
resource "volcengine_bandwidth_package" "foo" {
bandwidth_package_name = "tf-test"
billing_type = "PostPaidByBandwidth"
//billing_type = "PrePaid"
isp = "BGP"
description = "tftest-description"
bandwidth = 10
protocol = "IPv4"
//period = 1
security_protection_types = ["AntiDDoS_Enhanced"]
tags {
key = "tftest"
value = "tftest"
}
}
bandwidth_package_name = "acc-test-bp"
billing_type = "PostPaidByBandwidth"
isp = "BGP"
description = "acc-test"
bandwidth = 10
protocol = "IPv4"
security_protection_types = ["AntiDDoS_Enhanced"]
tags {
key = "k1"
value = "v1"
}
}
111 changes: 92 additions & 19 deletions example/bandwidthPackageAttachment/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,101 @@
resource "volcengine_eip_address" "foo" {
billing_type = "PostPaidByBandwidth"
bandwidth = 1
isp = "BGP"
name = "acc-eip"
description = "acc-test"
project_name = "default"
security_protection_types = ["AntiDDoS_Enhanced"]
billing_type = "PostPaidByBandwidth"
bandwidth = 1
isp = "BGP"
name = "acc-test-eip"
description = "acc-test"
project_name = "default"
}

resource "volcengine_bandwidth_package" "ipv4" {
bandwidth_package_name = "acc-test-bp"
billing_type = "PostPaidByBandwidth"
isp = "BGP"
description = "acc-test"
bandwidth = 2
protocol = "IPv4"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_bandwidth_package_attachment" "ipv4" {
allocation_id = volcengine_eip_address.foo.id
bandwidth_package_id = volcengine_bandwidth_package.ipv4.id
}

data "volcengine_zones" "foo" {
}

data "volcengine_images" "foo" {
os_type = "Linux"
visibility = "public"
instance_type_id = "ecs.g1.large"
}

resource "volcengine_vpc" "foo" {
vpc_name = "acc-test-vpc"
cidr_block = "172.16.0.0/16"
enable_ipv6 = true
}

resource "volcengine_subnet" "foo" {
subnet_name = "acc-test-subnet"
cidr_block = "172.16.0.0/24"
zone_id = data.volcengine_zones.foo.zones[0].id
vpc_id = volcengine_vpc.foo.id
ipv6_cidr_block = 1
}

resource "volcengine_security_group" "foo" {
vpc_id = volcengine_vpc.foo.id
security_group_name = "acc-test-security-group"
}

resource "volcengine_vpc_ipv6_gateway" "foo" {
vpc_id = volcengine_vpc.foo.id
name = "acc-test-1"
description = "test"
}

resource "volcengine_ecs_instance" "foo" {
image_id = data.volcengine_images.foo.images[0].image_id
instance_type = "ecs.g1.large"
instance_name = "acc-test-ecs-name"
password = "93f0cb0614Aab12"
instance_charge_type = "PostPaid"
system_volume_type = "ESSD_PL0"
system_volume_size = 40
subnet_id = volcengine_subnet.foo.id
security_group_ids = [volcengine_security_group.foo.id]
ipv6_address_count = 1
}

data "volcengine_vpc_ipv6_addresses" "foo" {
associated_instance_id = volcengine_ecs_instance.foo.id
}

resource "volcengine_bandwidth_package" "foo" {
bandwidth_package_name = "acc-test"
resource "volcengine_vpc_ipv6_address_bandwidth" "foo" {
ipv6_address = data.volcengine_vpc_ipv6_addresses.foo.ipv6_addresses.0.ipv6_address
billing_type = "PostPaidByBandwidth"
isp = "BGP"
description = "tftest-description"
bandwidth = 10
protocol = "IPv4"
bandwidth = 5
}

resource "volcengine_bandwidth_package" "ipv6" {
bandwidth_package_name = "acc-test-bp"
billing_type = "PostPaidByBandwidth"
isp = "BGP"
description = "acc-test"
bandwidth = 2
protocol = "IPv6"
tags {
key = "tftest"
value = "tftest"
key = "k1"
value = "v1"
}
security_protection_types = ["AntiDDoS_Enhanced"]
}

resource "volcengine_bandwidth_package_attachment" "foo" {
allocation_id = volcengine_eip_address.foo.id
bandwidth_package_id = volcengine_bandwidth_package.foo.id
}
allocation_id = volcengine_vpc_ipv6_address_bandwidth.foo.id
bandwidth_package_id = volcengine_bandwidth_package.ipv6.id
}
10 changes: 7 additions & 3 deletions example/cen/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
resource "volcengine_cen" "foo" {
cen_name = "tf-test-3"
description = "tf-test"
cen_name = "acc-test-cen"
description = "acc-test"
project_name = "default"
}
tags {
key = "k1"
value = "v1"
}
}
28 changes: 18 additions & 10 deletions example/cenAttachInstance/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
resource "volcengine_cen_attach_instance" "foo" {
cen_id = "cen-12ar8uclj68sg17q7y20v9gil"
instance_id = "vpc-2fe5dpn0av2m859gp68rhk2dc"
instance_type = "VPC"
instance_region_id = "cn-beijing"
resource "volcengine_vpc" "foo" {
vpc_name = "acc-test-vpc"
cidr_block = "172.16.0.0/16"
}

resource "volcengine_cen" "foo" {
cen_name = "acc-test-cen"
description = "acc-test"
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_cen_attach_instance" "foo1" {
cen_id = "cen-12ar8uclj68sg17q7y20v9gil"
instance_id = "vpc-in66ktl5t24g8gbssz0sqva1"
instance_type = "VPC"
resource "volcengine_cen_attach_instance" "foo" {
cen_id = volcengine_cen.foo.id
instance_id = volcengine_vpc.foo.id
instance_region_id = "cn-beijing"
}
instance_type = "VPC"
}
22 changes: 13 additions & 9 deletions example/cenBandwidthPackage/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
resource "volcengine_cen_bandwidth_package" "foo" {
local_geographic_region_set_id = "China"
peer_geographic_region_set_id = "China"
bandwidth = 32
cen_bandwidth_package_name = "tf-test"
description = "tf-test1"
billing_type = "PrePaid"
period_unit = "Year"
period = 1
project_name = "default"
}
peer_geographic_region_set_id = "China"
bandwidth = 2
cen_bandwidth_package_name = "acc-test-cen-bp"
description = "acc-test"
billing_type = "PrePaid"
period_unit = "Month"
period = 1
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}
32 changes: 29 additions & 3 deletions example/cenBandwidthPackageAssociate/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
resource "volcengine_cen" "foo" {
cen_name = "acc-test-cen"
description = "acc-test"
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_cen_bandwidth_package" "foo" {
local_geographic_region_set_id = "China"
peer_geographic_region_set_id = "China"
bandwidth = 2
cen_bandwidth_package_name = "acc-test-cen-bp"
description = "acc-test"
billing_type = "PrePaid"
period_unit = "Month"
period = 1
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_cen_bandwidth_package_associate" "foo" {
cen_bandwidth_package_id = "cbp-2bzeew3s8p79c2dx0eeohej4x"
cen_id = "cen-2bzrl3srxsv0g2dx0efyoojn3"
}
cen_bandwidth_package_id = volcengine_cen_bandwidth_package.foo.id
cen_id = volcengine_cen.foo.id
}
42 changes: 37 additions & 5 deletions example/cenInterRegionBandwidth/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
resource "volcengine_cen" "foo" {
cen_name = "acc-test-cen"
description = "acc-test"
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_cen_bandwidth_package" "foo" {
local_geographic_region_set_id = "China"
peer_geographic_region_set_id = "China"
bandwidth = 5
cen_bandwidth_package_name = "acc-test-cen-bp"
description = "acc-test"
billing_type = "PrePaid"
period_unit = "Month"
period = 1
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_cen_bandwidth_package_associate" "foo" {
cen_bandwidth_package_id = volcengine_cen_bandwidth_package.foo.id
cen_id = volcengine_cen.foo.id
}

resource "volcengine_cen_inter_region_bandwidth" "foo" {
cen_id = "cen-274vsbhwvvb407fap8sp611w7"
local_region_id = "cn-north-3"
peer_region_id = "cn-zhangjiakou"
bandwidth = 1
}
cen_id = volcengine_cen.foo.id
local_region_id = "cn-beijing"
peer_region_id = "cn-shanghai"
bandwidth = 2
depends_on = [volcengine_cen_bandwidth_package_associate.foo]
}
Loading

0 comments on commit 523b01e

Please sign in to comment.