-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Terraform ProfitBricks Builder #7943
Merged
stack72
merged 12 commits into
hashicorp:master
from
StackPointCloud:terraform-provider-profitbricks
Jan 18, 2017
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa0b8fc
Terraform ProfitBricks Builder
3b907d6
Merge remote-tracking branch 'upstream/master' into terraform-provide…
940b3f6
make fmt
5d63bd9
Merge remote-tracking branch 'upstream/master' into terraform-provide…
9c82c60
Merge remote-tracking branch 'upstream/master' into terraform-provide…
5996086
Merge remote-tracking branch 'upstream/master' into terraform-provide…
ac2f78f
Merge remote-tracking branch 'upstream/master' into terraform-provide…
5a6dd69
Merge remote-tracking branch 'upstream/master' into terraform-provide…
379a6cc
Addressing PR remarks
afabb26
Merge remote-tracking branch 'upstream/master' into terraform-provide…
21831c0
Merge remote-tracking branch 'upstream/master' into terraform-provide…
cff8e3f
Removed importers
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 provider_profitbricks | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/builtin/providers/profitbricks" | ||
"github.com/hashicorp/terraform/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: profitbricks.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,22 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"github.com/profitbricks/profitbricks-sdk-go" | ||
"log" | ||
"strconv" | ||
) | ||
|
||
type Config struct { | ||
Username string | ||
Password string | ||
Timeout int | ||
} | ||
|
||
// Client() returns a new client for accessing digital ocean. | ||
func (c *Config) Client() (string, error) { | ||
profitbricks.SetAuth(c.Username, c.Password) | ||
profitbricks.SetDepth("5") | ||
log.Printf("[DEBUG] Username and password %s : %s", c.Username, c.Password) | ||
log.Printf("[DEBUG] Timeout %d", c.Timeout) | ||
return c.Username + "," + c.Password + "," + strconv.Itoa(c.Timeout), nil | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_datacenter_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksDatacenter_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_datacenter.foobar" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksDatacenterDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitBricksDatacenterConfig_basic, "datacenter"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_firewall_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksFirewall_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_firewall.foobar" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksFirewallDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksFirewallConfig_basic, "firewall"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_ipblock_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksIPBlock_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_ipblock.webserver_ip" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksIPBlockDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksIPBlockConfig_basic, "ipblock"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_lan_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksLan_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_lan.webserver_lan" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksLanDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksLanConfig_basic, "lan"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_loadbalancer_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksLoadbalancer_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_loadbalancer.example" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksLoadbalancerDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksLoadbalancerConfig_basic, "loadbalancer"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_nic_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksNic_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_nic.database_nic" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksNicDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksNicConfig_basic, "nic"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
35 changes: 35 additions & 0 deletions
35
builtin/providers/profitbricks/import_profitbricks_server_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,35 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksServer_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_server.webserver" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksServerDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksServerConfig_basic, "server"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"nic", | ||
"volume", | ||
"boot_volume", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
builtin/providers/profitbricks/import_profitbricks_volume_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,30 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccProfitBricksVolume_importBasic(t *testing.T) { | ||
resourceName := "profitbricks_volume.database_volume" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDProfitBricksVolumeDestroyCheck, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: fmt.Sprintf(testAccCheckProfitbricksVolumeConfig_basic, "volume"), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
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,53 @@ | ||
package profitbricks | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// Provider returns a schema.Provider for DigitalOcean. | ||
func Provider() terraform.ResourceProvider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"username": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_USERNAME", nil), | ||
Description: "Profitbricks username for API operations.", | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_PASSWORD", nil), | ||
Description: "Profitbricks password for API operations.", | ||
}, | ||
"timeout": { | ||
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. Should we set a default timeout? |
||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
}, | ||
|
||
ResourcesMap: map[string]*schema.Resource{ | ||
"profitbricks_datacenter": resourceProfitBricksDatacenter(), | ||
"profitbricks_ipblock": resourceProfitBricksIPBlock(), | ||
"profitbricks_firewall": resourceProfitBricksFirewall(), | ||
"profitbricks_lan": resourceProfitBricksLan(), | ||
"profitbricks_loadbalancer": resourceProfitBricksLoadbalancer(), | ||
"profitbricks_nic": resourceProfitBricksNic(), | ||
"profitbricks_server": resourceProfitBricksServer(), | ||
"profitbricks_volume": resourceProfitBricksVolume(), | ||
}, | ||
|
||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
config := Config{ | ||
Username: d.Get("username").(string), | ||
Password: d.Get("password").(string), | ||
Timeout: d.Get("timeout").(int), | ||
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. We should check that this is set otherwise, it will be a 0 being passed - is that an issue? |
||
} | ||
|
||
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,39 @@ | ||
package profitbricks | ||
|
||
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{ | ||
"profitbricks": 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("PROFITBRICKS_USERNAME"); v == "" { | ||
t.Fatal("PROFITBRICKS_USERNAME must be set for acceptance tests") | ||
} | ||
|
||
if v := os.Getenv("PROFITBRICKS_PASSWORD"); v == "" { | ||
t.Fatal("PROFITBRICKS_PASSWORD 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.
I don't think we should log the password here