-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Add alicloud provider, including resource and examples of alicloud provider #10761
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1908d61
Add aliyun provider, including resource and examples of aliyun provider
xiaozhu36 a3cf028
Merge branch 'master' of github.com:hashicorp/terraform into xz-dev
xiaozhu36 7af9f3e
Add aliyun provider, including resource,examples and docs of aliyun p…
xiaozhu36 79e00bd
modify aliyun provider, and add examples and docs of aliyun provider
xiaozhu36 eadb81e
commit alicloud go sdk
xiaozhu36 93d72e9
remove alicloud sdk
xiaozhu36 5e52f37
Merge branch 'master' of https://github.com/hashicorp/terraform into …
xiaozhu36 e35f710
improve some defects according to last TF feedback
xiaozhu36 d7f5163
merge terraform master
xiaozhu36 4116c20
vendor the SDK correctly and update the dependencies
xiaozhu36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/builtin/providers/alicloud" | ||
"github.com/hashicorp/terraform/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: alicloud.Provider, | ||
}) | ||
} |
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,52 @@ | ||
package alicloud | ||
|
||
import ( | ||
"github.com/denverdino/aliyungo/common" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
type InstanceNetWork string | ||
|
||
const ( | ||
ClassicNet = InstanceNetWork("classic") | ||
VpcNet = InstanceNetWork("vpc") | ||
) | ||
|
||
const defaultTimeout = 120 | ||
|
||
func getRegion(d *schema.ResourceData, meta interface{}) common.Region { | ||
return meta.(*AliyunClient).Region | ||
} | ||
|
||
func notFoundError(err error) bool { | ||
if e, ok := err.(*common.Error); ok && (e.StatusCode == 404 || e.ErrorResponse.Message == "Not found") { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// Protocal represents network protocal | ||
type Protocal string | ||
|
||
// Constants of protocal definition | ||
const ( | ||
Http = Protocal("http") | ||
Https = Protocal("https") | ||
Tcp = Protocal("tcp") | ||
Udp = Protocal("udp") | ||
) | ||
|
||
// ValidProtocals network protocal list | ||
var ValidProtocals = []Protocal{Http, Https, Tcp, Udp} | ||
|
||
// simple array value check method, support string type only | ||
func isProtocalValid(value string) bool { | ||
res := false | ||
for _, v := range ValidProtocals { | ||
if string(v) == value { | ||
res = true | ||
} | ||
} | ||
return res | ||
} |
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,103 @@ | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/denverdino/aliyungo/common" | ||
"github.com/denverdino/aliyungo/ecs" | ||
"github.com/denverdino/aliyungo/slb" | ||
) | ||
|
||
// Config of aliyun | ||
type Config struct { | ||
AccessKey string | ||
SecretKey string | ||
Region common.Region | ||
} | ||
|
||
// AliyunClient of aliyun | ||
type AliyunClient struct { | ||
Region common.Region | ||
ecsconn *ecs.Client | ||
vpcconn *ecs.Client | ||
slbconn *slb.Client | ||
} | ||
|
||
// Client for AliyunClient | ||
func (c *Config) Client() (*AliyunClient, error) { | ||
err := c.loadAndValidate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ecsconn, err := c.ecsConn() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
slbconn, err := c.slbConn() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vpcconn, err := c.vpcConn() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &AliyunClient{ | ||
Region: c.Region, | ||
ecsconn: ecsconn, | ||
vpcconn: vpcconn, | ||
slbconn: slbconn, | ||
}, nil | ||
} | ||
|
||
func (c *Config) loadAndValidate() error { | ||
err := c.validateRegion() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) validateRegion() error { | ||
|
||
for _, valid := range common.ValidRegions { | ||
if c.Region == valid { | ||
return nil | ||
} | ||
} | ||
|
||
return fmt.Errorf("Not a valid region: %s", c.Region) | ||
} | ||
|
||
func (c *Config) ecsConn() (*ecs.Client, error) { | ||
client := ecs.NewClient(c.AccessKey, c.SecretKey) | ||
_, err := client.DescribeRegions() | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return client, nil | ||
} | ||
|
||
func (c *Config) slbConn() (*slb.Client, error) { | ||
client := slb.NewClient(c.AccessKey, c.SecretKey) | ||
|
||
return client, nil | ||
} | ||
|
||
func (c *Config) vpcConn() (*ecs.Client, error) { | ||
_, err := c.ecsConn() | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client := &ecs.Client{} | ||
client.Init("https://vpc.aliyuncs.com/", "2016-04-28", c.AccessKey, c.SecretKey) | ||
return client, nil | ||
} |
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,36 @@ | ||
package alicloud | ||
|
||
import "github.com/denverdino/aliyungo/ecs" | ||
|
||
//Modify with your Access Key Id and Access Key Secret | ||
|
||
const ( | ||
TestAccessKeyId = "****" | ||
TestAccessKeySecret = "****" | ||
TestInstanceId = "MY_TEST_INSTANCE_ID" | ||
TestSecurityGroupId = "MY_TEST_SECURITY_GROUP_ID" | ||
TestImageId = "MY_TEST_IMAGE_ID" | ||
TestAccountId = "MY_TEST_ACCOUNT_ID" //Get from https://account.console.aliyun.com | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again this should not be hard coded |
||
|
||
TestIAmRich = true | ||
TestQuick = false | ||
) | ||
|
||
var testClient *ecs.Client | ||
|
||
func NewTestClient() *ecs.Client { | ||
if testClient == nil { | ||
testClient = ecs.NewClient(TestAccessKeyId, TestAccessKeySecret) | ||
} | ||
return testClient | ||
} | ||
|
||
var testDebugClient *ecs.Client | ||
|
||
func NewTestClientForDebug() *ecs.Client { | ||
if testDebugClient == nil { | ||
testDebugClient = ecs.NewClient(TestAccessKeyId, TestAccessKeySecret) | ||
testDebugClient.SetDebug(true) | ||
} | ||
return testDebugClient | ||
} |
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,30 @@ | ||
package alicloud | ||
|
||
const ( | ||
// common | ||
Notfound = "Not found" | ||
// ecs | ||
InstanceNotfound = "Instance.Notfound" | ||
// disk | ||
DiskIncorrectStatus = "IncorrectDiskStatus" | ||
DiskCreatingSnapshot = "DiskCreatingSnapshot" | ||
InstanceLockedForSecurity = "InstanceLockedForSecurity" | ||
// eip | ||
EipIncorrectStatus = "IncorrectEipStatus" | ||
InstanceIncorrectStatus = "IncorrectInstanceStatus" | ||
HaVipIncorrectStatus = "IncorrectHaVipStatus" | ||
// slb | ||
LoadBalancerNotFound = "InvalidLoadBalancerId.NotFound" | ||
|
||
// security_group | ||
InvalidInstanceIdAlreadyExists = "InvalidInstanceId.AlreadyExists" | ||
InvalidSecurityGroupIdNotFound = "InvalidSecurityGroupId.NotFound" | ||
SgDependencyViolation = "DependencyViolation" | ||
|
||
//Nat gateway | ||
NatGatewayInvalidRegionId = "Invalid.RegionId" | ||
DependencyViolationBandwidthPackages = "DependencyViolation.BandwidthPackages" | ||
|
||
// vswitch | ||
VswitcInvalidRegionId = "InvalidRegionId.NotFound" | ||
) |
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,32 @@ | ||
package alicloud | ||
|
||
type GroupRuleDirection string | ||
|
||
const ( | ||
GroupRuleIngress = GroupRuleDirection("ingress") | ||
GroupRuleEgress = GroupRuleDirection("egress") | ||
) | ||
|
||
type GroupRuleIpProtocol string | ||
|
||
const ( | ||
GroupRuleTcp = GroupRuleIpProtocol("tcp") | ||
GroupRuleUdp = GroupRuleIpProtocol("udp") | ||
GroupRuleIcmp = GroupRuleIpProtocol("icmp") | ||
GroupRuleGre = GroupRuleIpProtocol("gre") | ||
GroupRuleAll = GroupRuleIpProtocol("all") | ||
) | ||
|
||
type GroupRuleNicType string | ||
|
||
const ( | ||
GroupRuleInternet = GroupRuleNicType("internet") | ||
GroupRuleIntranet = GroupRuleNicType("intranet") | ||
) | ||
|
||
type GroupRulePolicy string | ||
|
||
const ( | ||
GroupRulePolicyAccept = GroupRulePolicy("accept") | ||
GroupRulePolicyDrop = GroupRulePolicy("drop") | ||
) |
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.
I don't think we should hard code these - we should use environment variables to pass these in - this is a standard practice across providers