Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Vultr provider 馃惁 #278

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A CLI tool that generates `tf` and `tfstate` files based on existing infrastruct
* [Heroku](#use-with-heroku)
* [Linode](#use-with-linode)
* [OpenStack](#use-with-openstack)
* [Vultr](#use-with-vultr)
* Infrastructure Software
* [Kubernetes](#use-with-kubernetes)
* [RabbitMQ](#use-with-rabbitmq)
Expand Down Expand Up @@ -168,6 +169,7 @@ Links to download Terraform Providers:
* Heroku provider >2.2.1 - [here](https://releases.hashicorp.com/terraform-provider-heroku/)
* Linode provider >1.8.0 - [here](https://releases.hashicorp.com/terraform-provider-linode/)
* OpenStack provider >1.21.1 - [here](https://releases.hashicorp.com/terraform-provider-openstack/)
* Vultr provider >1.0.5 - [here](https://releases.hashicorp.com/terraform-provider-vultr/)
* Infrastructure Software
* Kubernetes provider >=1.9.0 - [here](https://releases.hashicorp.com/terraform-provider-kubernetes/)
* Network
Expand Down Expand Up @@ -697,6 +699,40 @@ List of supported OpenStack services:
* `openstack_networking_secgroup_v2`
* `openstack_networking_secgroup_rule_v2`

### Use with Vultr

Example:

```
export VULTR_API_KEY=[VULTR_API_KEY]
./terraformer import vultr -r server
```

List of supported Vultr resources:

* `bare_metal_server`
* `vultr_bare_metal_server`
* `block_storage`
* `vultr_block_storage`
* `dns_domain`
* `vultr_dns_domain`
* `firewall_group`
* `vultr_firewall_group`
* `network`
* `vultr_network`
* `reserved_ip`
* `vultr_reserved_ip`
* `server`
* `vultr_server`
* `snapshot`
* `vultr_snapshot`
* `ssh_key`
* `vultr_ssh_key`
* `startup_script`
* `vultr_startup_script`
* `user`
* `vultr_user`

### Use with Kubernetes

Example:
Expand Down
52 changes: 52 additions & 0 deletions cmd/provider_cmd_vultr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd

import (
vultr_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/vultr"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/spf13/cobra"
)

func newCmdVultrImporter(options ImportOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "vultr",
Short: "Import current state to Terraform configuration from Vultr",
Long: "Import current state to Terraform configuration from Vultr",
RunE: func(cmd *cobra.Command, args []string) error {
provider := newVultrProvider()
err := Import(provider, options, []string{})
if err != nil {
return err
}
return nil
},
}

cmd.AddCommand(listCmd(newVultrProvider()))
cmd.PersistentFlags().BoolVarP(&options.Connect, "connect", "c", true, "")
cmd.PersistentFlags().StringSliceVarP(&options.Resources, "resources", "r", []string{}, "server")
cmd.PersistentFlags().StringVarP(&options.PathPattern, "path-pattern", "p", DefaultPathPattern, "{output}/{provider}/custom/{service}/")
cmd.PersistentFlags().StringVarP(&options.PathOutput, "path-output", "o", DefaultPathOutput, "")
cmd.PersistentFlags().StringVarP(&options.State, "state", "s", DefaultState, "local or bucket")
cmd.PersistentFlags().StringVarP(&options.Bucket, "bucket", "b", "", "gs://terraform-state")
cmd.PersistentFlags().StringSliceVarP(&options.Filter, "filter", "f", []string{}, "vultr_server=name1:name2:name3")

return cmd
}

func newVultrProvider() terraform_utils.ProviderGenerator {
return &vultr_terraforming.VultrProvider{}
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func providerImporterSubcommands() []func(options ImportOptions) *cobra.Command
newCmdHerokuImporter,
newCmdLinodeImporter,
newCmdOpenStackImporter,
newCmdVultrImporter,
// Infrastructure Software
newCmdKubernetesImporter,
newCmdRabbitMQImporter,
Expand Down Expand Up @@ -76,6 +77,7 @@ func providerGenerators() map[string]func() terraform_utils.ProviderGenerator {
newHerokuProvider,
newLinodeProvider,
newOpenStackProvider,
newVultrProvider,
// Infrastructure Software
newKubernetesProvider,
newRabbitMQProvider,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/google/go-github/v25 v25.1.3
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gophercloud/gophercloud v0.4.1-0.20190920074709-6e93a6ba3b09
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.9.2
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-version v1.2.0 // indirect
Expand All @@ -51,6 +50,7 @@ require (
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
github.com/ulikunitz/xz v0.5.6 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vultr/govultr v0.1.6
github.com/zclconf/go-cty v1.1.0
github.com/zorkian/go-datadog-api v2.24.0+incompatible
go.opencensus.io v0.22.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26/go.mod h1:++
github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-retryablehttp v0.5.2/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.6.3 h1:tuulM+WnToeqa05z83YLmKabZxrySOmJAd4mJ+s2Nfg=
github.com/hashicorp/go-retryablehttp v0.6.3/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
Expand Down Expand Up @@ -497,6 +499,8 @@ github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6Ac
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vultr/govultr v0.1.6 h1:FZqwbph8iir4IwUjC/bZfnulM3OejhNoI2ebYUlvNCs=
github.com/vultr/govultr v0.1.6/go.mod h1:glSLa57Jdj5s860EEc6+DEBbb/t3aUOKnB4gVPmDVlQ=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
Expand Down
49 changes: 49 additions & 0 deletions providers/vultr/bare_metal_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vultr

import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/vultr/govultr"
)

type BareMetalServerGenerator struct {
VultrService
}

func (g BareMetalServerGenerator) createResources(serverList []govultr.BareMetalServer) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, server := range serverList {
resources = append(resources, terraform_utils.NewSimpleResource(
server.BareMetalServerID,
server.BareMetalServerID,
"vultr_bare_metal_server",
"vultr",
[]string{}))
}
return resources
}

func (g *BareMetalServerGenerator) InitResources() error {
client := g.generateClient()
output, err := client.BareMetalServer.List(context.Background())
if err != nil {
return err
}
g.Resources = g.createResources(output)
return nil
}
49 changes: 49 additions & 0 deletions providers/vultr/block_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vultr

import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/vultr/govultr"
)

type BlockStorageGenerator struct {
VultrService
}

func (g BlockStorageGenerator) createResources(blockStorageList []govultr.BlockStorage) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, blockStorage := range blockStorageList {
resources = append(resources, terraform_utils.NewSimpleResource(
blockStorage.BlockStorageID,
blockStorage.BlockStorageID,
"vultr_block_storage",
"vultr",
[]string{}))
}
return resources
}

func (g *BlockStorageGenerator) InitResources() error {
client := g.generateClient()
output, err := client.BlockStorage.List(context.Background())
if err != nil {
return err
}
g.Resources = g.createResources(output)
return nil
}
49 changes: 49 additions & 0 deletions providers/vultr/dns_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vultr

import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/vultr/govultr"
)

type DNSDomainGenerator struct {
VultrService
}

func (g DNSDomainGenerator) createResources(domainList []govultr.DNSDomain) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, domain := range domainList {
resources = append(resources, terraform_utils.NewSimpleResource(
domain.Domain,
domain.Domain,
"vultr_dns_domain",
"vultr",
[]string{}))
}
return resources
}

func (g *DNSDomainGenerator) InitResources() error {
client := g.generateClient()
output, err := client.DNSDomain.List(context.Background())
if err != nil {
return err
}
g.Resources = g.createResources(output)
return nil
}
49 changes: 49 additions & 0 deletions providers/vultr/firewall_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vultr

import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/vultr/govultr"
)

type FirewallGroupGenerator struct {
VultrService
}

func (g FirewallGroupGenerator) createResources(firewallGroup []govultr.FirewallGroup) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, firewallGroup := range firewallGroup {
resources = append(resources, terraform_utils.NewSimpleResource(
firewallGroup.FirewallGroupID,
firewallGroup.FirewallGroupID,
"vultr_firewall_group",
"vultr",
[]string{}))
}
return resources
}

func (g *FirewallGroupGenerator) InitResources() error {
client := g.generateClient()
output, err := client.FirewallGroup.List(context.Background())
if err != nil {
return err
}
g.Resources = g.createResources(output)
return nil
}