-
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
Provider Oneandone #13633
Merged
+11,355
−9
Merged
Provider Oneandone #13633
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8569766
Terraform Provider 1&1
5d9f06c
Merge remote-tracking branch 'upstream/master' into oneandone
fec36f9
Addressing pull request remarks
d9d2c1d
Fixed imports
1bf8a5d
Fixing remarks
5dd848f
Test optimiziation
d6d3477
Merge remote-tracking branch 'upstream/master' into oneandone
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
package oneandone | ||
|
||
import ( | ||
"github.com/1and1/oneandone-cloudserver-sdk-go" | ||
) | ||
|
||
type Config struct { | ||
Token string | ||
Retries int | ||
Endpoint string | ||
API *oneandone.API | ||
} | ||
|
||
func (c *Config) Client() (*Config, error) { | ||
token := oneandone.SetToken(c.Token) | ||
|
||
if len(c.Endpoint) > 0 { | ||
c.API = oneandone.New(token, c.Endpoint) | ||
} else { | ||
c.API = oneandone.New(token, oneandone.BaseUrl) | ||
} | ||
|
||
return c, 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,56 @@ | ||
package oneandone | ||
|
||
import ( | ||
"github.com/1and1/oneandone-cloudserver-sdk-go" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func Provider() terraform.ResourceProvider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"token": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_TOKEN", nil), | ||
Description: "1&1 token for API operations.", | ||
}, | ||
"retries": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 50, | ||
DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_RETRIES", nil), | ||
}, | ||
"endpoint": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: oneandone.BaseUrl, | ||
DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_ENDPOINT", nil), | ||
}, | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"oneandone_server": resourceOneandOneServer(), | ||
"oneandone_firewall_policy": resourceOneandOneFirewallPolicy(), | ||
"oneandone_private_network": resourceOneandOnePrivateNetwork(), | ||
"oneandone_public_ip": resourceOneandOnePublicIp(), | ||
"oneandone_shared_storage": resourceOneandOneSharedStorage(), | ||
"oneandone_monitoring_policy": resourceOneandOneMonitoringPolicy(), | ||
"oneandone_loadbalancer": resourceOneandOneLoadbalancer(), | ||
"oneandone_vpn": resourceOneandOneVPN(), | ||
}, | ||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
var endpoint string | ||
if d.Get("endpoint").(string) != oneandone.BaseUrl { | ||
endpoint = d.Get("endpoint").(string) | ||
} | ||
config := Config{ | ||
Token: d.Get("token").(string), | ||
Retries: d.Get("retries").(int), | ||
Endpoint: endpoint, | ||
} | ||
return config.Client() | ||
} |
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 oneandone | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// | ||
var testAccProviders map[string]terraform.ResourceProvider | ||
var testAccProvider *schema.Provider | ||
|
||
func init() { | ||
testAccProvider = Provider().(*schema.Provider) | ||
testAccProviders = map[string]terraform.ResourceProvider{ | ||
"oneandone": testAccProvider, | ||
} | ||
} | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := Provider().(*schema.Provider).InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func TestProvider_impl(t *testing.T) { | ||
var _ terraform.ResourceProvider = Provider() | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("ONEANDONE_TOKEN"); v == "" { | ||
t.Fatal("ONEANDONE_TOKEN must be set for acceptance tests") | ||
} | ||
} |
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.
Retries are passed to the
Config
struct but not actually used in there?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.
"retries" are not used in
provider.go
but are used pretty much in every 1and1 resource.