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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ionoscloud support #1600

Merged
merged 46 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4b3572e
[WIP] add ionoscloud support
iblindu Jul 1, 2022
5c52f49
[WIP] add ionoscloud support
iblindu Jul 4, 2022
db05c66
fix: fix set dcId for servers and lan
cristiGuranIonos Jul 7, 2022
c1badd4
Fix/add datacenter id field
cristiGuranIonos Jul 7, 2022
4e888d8
Merge branch 'master' into add-ionoscloud-support
iblindu Jul 27, 2022
9a25a6b
vendor update
iblindu Jul 27, 2022
bb5c678
docs: added documentations for ionoscloud
iblindu Jul 27, 2022
1ccfadd
feat: add nic and volume
cristiGuranIonos Sep 23, 2022
1384456
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Oct 20, 2022
1c29f43
fix: remove unnecessary prints from server.go file (#3)
adeatcu-ionos Oct 24, 2022
1fa49c1
feat: implement IP Block (#4)
adeatcu-ionos Oct 24, 2022
135894e
feat: implement backup unit (#2)
adeatcu-ionos Oct 24, 2022
7a1621b
feat: Implement K8s cluster (#5)
adeatcu-ionos Oct 25, 2022
b830c52
feat: implement Kubernetes Nodepool (#6)
adeatcu-ionos Oct 25, 2022
2b27022
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Oct 26, 2022
2319317
fix: resolve import inconsistency (#7)
adeatcu-ionos Oct 26, 2022
d8429ca
fix: fix IONOS_TOKEN authentication (#9)
adeatcu-ionos Oct 28, 2022
93566d4
feat: add extra checks for resources (#10)
adeatcu-ionos Nov 2, 2022
fb3a35c
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Nov 2, 2022
e187213
feat: implement target group (#8)
adeatcu-ionos Nov 2, 2022
2cdf85d
fix: remove unnecessary check and test statement (#13)
adeatcu-ionos Nov 2, 2022
dff81da
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Nov 3, 2022
6ea1cb4
feat: implement network load balancer (#14)
adeatcu-ionos Nov 3, 2022
42bfaa9
feat: implement NAT gateway (#12)
adeatcu-ionos Nov 4, 2022
532e4ae
feat: implement group (#11)
adeatcu-ionos Nov 4, 2022
4c8621f
feat: implement application load balancer (#15)
adeatcu-ionos Nov 7, 2022
d532d64
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Dec 5, 2022
742f0d7
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Dec 13, 2022
54bcd5b
feat: fix server corner cases. k8s server should not be written to plan.
cristiGuranIonos Dec 13, 2022
091b43c
Implement firewall resource, fix name typo, change nic logic (#16)
adeatcu-ionos Dec 15, 2022
744a2e6
implement NLB forwarding rule (#17)
adeatcu-ionos Dec 15, 2022
1ad0778
Implement load balancer (#18)
adeatcu-ionos Dec 19, 2022
7c87015
feat: implement NAT gateway rule (#19)
adeatcu-ionos Dec 19, 2022
f76b531
fix: rename generator string (#20)
adeatcu-ionos Dec 21, 2022
e5d573c
feat: rename variable, add condition if server valid, firewall link t…
cristiGuranIonos Dec 23, 2022
054dd97
feat: improve doc
cristiGuranIonos Dec 23, 2022
ac4eba1
feat: use variables for hardcoded strings
cristiGuranIonos Dec 23, 2022
ed0c7a8
feat: link remaining resources
cristiGuranIonos Dec 23, 2022
2f34591
Merge pull request #21 from ionos-cloud/fix/small_fixes_server_variab…
cristiGuranIonos Dec 23, 2022
74e4c26
doc: update README.md
adeatcu-ionos Jan 6, 2023
71d1827
fix: add links to supported resources
cristiGuranIonos Jan 13, 2023
0b73580
fix: add links to supported resources
cristiGuranIonos Jan 13, 2023
710b9a6
Merge pull request #22 from ionos-cloud/fix/add_links_to_resources
cristiGuranIonos Jan 13, 2023
c646ce4
Merge branch 'master' into add-ionoscloud-support
adeatcu-ionos Feb 1, 2023
c07585a
fix: remove 'Printf' calls from utils.go (#23)
adeatcu-ionos Feb 1, 2023
dbd0699
refactor: fix linter errors (#24)
adeatcu-ionos Feb 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ A CLI tool that generates `tf`/`json` and `tfstate` files based on existing infr
* [TencentCloud](/docs/tencentcloud.md)
* [Vultr](/docs/vultr.md)
* [Yandex Cloud](/docs/yandex.md)
* [Ionos Cloud](/docs/ionoscloud.md)
* Infrastructure Software
* [Kubernetes](/docs/kubernetes.md)
* [OctopusDeploy](/docs/octopus.md)
Expand Down Expand Up @@ -288,6 +289,7 @@ Links to download Terraform Providers:
* TencentCloud provider >1.50.0 - [here](https://releases.hashicorp.com/terraform-provider-tencentcloud/)
* Vultr provider >1.0.5 - [here](https://releases.hashicorp.com/terraform-provider-vultr/)
* Yandex provider >0.42.0 - [here](https://releases.hashicorp.com/terraform-provider-yandex/)
* Ionoscloud provider >6.3.3 - [here](https://github.com/ionos-cloud/terraform-provider-ionoscloud/releases)
* Infrastructure Software
* Kubernetes provider >=1.9.0 - [here](https://releases.hashicorp.com/terraform-provider-kubernetes/)
* RabbitMQ provider >=1.1.0 - [here](https://releases.hashicorp.com/terraform-provider-rabbitmq/)
Expand Down
45 changes: 45 additions & 0 deletions cmd/provider_cmd_ionoscloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 (
ionoscloud_terraformer "github.com/GoogleCloudPlatform/terraformer/providers/ionoscloud"

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

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

cmd.AddCommand(listCmd(newIonosCloudProvider()))
baseProviderFlags(cmd.PersistentFlags(), &options, "app,addon", "app=name1:name2:name3")
return cmd
}

func newIonosCloudProvider() terraformutils.ProviderGenerator {
return &ionoscloud_terraformer.IonosCloudProvider{}
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func providerImporterSubcommands() []func(options ImportOptions) *cobra.Command
newCmdTencentCloudImporter,
newCmdVultrImporter,
newCmdYandexImporter,
newCmdIonosCloudImporter,
// Infrastructure Software
newCmdKubernetesImporter,
newCmdOctopusDeployImporter,
Expand Down
47 changes: 47 additions & 0 deletions docs/ionoscloud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Use with IONOS Cloud

## Authentication

Proper credential must be configured, before it can be used.

You can set the environment variables for *HTTP basic authentication*:

export IONOS_USERNAME="username"
export IONOS_PASSWORD="password"

Or you can use *token authentication*:

export IONOS_TOKEN="token"


## List of supported IONOS Cloud resources

* [`datacenter`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/datacenter)
* [`lan`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/lan)
* [`server`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/server)
* [`volume`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/volume)
* [`nic`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/nic)
* [`firewall`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/firewall)
* [`group`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/group)
* [`backup_unit`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/backup_unit)
* [`ipblock`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/ipblock)
* [`k8s_cluster`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/k8s_cluster)
* [`k8s_node_pool`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/k8s_node_pool)
* [`target_group`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/target_group)
* [`networkloadbalancer`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/networkloadbalancer)
* [`natgateway`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/natgateway)
* [`natgateway_rule`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/natgateway_rule)
* [`application_loadbalancer`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/application_loadbalancer)
* [`networkloadbalancer_forwardingrule`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/networkloadbalancer_forwardingrule)
* [`loadbalancer`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/loadbalancer)
* [`dbaas_pgsql_cluster`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_pgsql_cluster)

We allow only resources that provide valid terraform plans to be imported.
If you do not see your resource in the tf plan, please enable TF_LOG=debug and check logs
for a message that will let you know why the resource was not imported.

#### Notes:
- A server must have a `NIC` and a `volume` attached to be allowed to be imported by terraformer.
- A server must also have a `BootVolume` set.


2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ require (
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 // indirect
github.com/honeycombio/terraform-provider-honeycombio v0.10.0
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.0.3
github.com/ionos-cloud/sdk-go/v6 v6.1.3
github.com/jefferai/jsonx v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0
github.com/jonboydell/logzio_client v1.2.0
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,13 @@ github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.0.3 h1:ahzztBNJ1IcQL+hdzhek6234P4ednkqdOgTsfB0nEfE=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.0.3/go.mod h1:87cFAQViqjorhuafmYIDCmCTr5GiaqDB7qr09K1gdOU=
github.com/ionos-cloud/sdk-go/v6 v6.1.0 h1:0EZz5H+t6W23zHt6dgHYkKavr72/30O9nA97E3FZaS4=
github.com/ionos-cloud/sdk-go/v6 v6.1.0/go.mod h1:Ox3W0iiEz0GHnfY9e5LmAxwklsxguuNFEUSu0gVRTME=
github.com/ionos-cloud/sdk-go/v6 v6.1.3 h1:vb6yqdpiqaytvreM0bsn2pXw+1YDvEk2RKSmBAQvgDQ=
github.com/ionos-cloud/sdk-go/v6 v6.1.3/go.mod h1:Ox3W0iiEz0GHnfY9e5LmAxwklsxguuNFEUSu0gVRTME=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jefferai/jsonx v1.0.1 h1:GvWkLWihoLqDG0BSP45TUQJH9qsINX50PVrFULgpc/I=
github.com/jefferai/jsonx v1.0.1/go.mod h1:yFo3l2fcm7cZVHGq3HKLXE+Pd4RWuRjNBDHksM7XekQ=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
Expand Down
55 changes: 55 additions & 0 deletions providers/ionoscloud/application_load_balancer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ionoscloud

import (
"context"
"log"

"github.com/GoogleCloudPlatform/terraformer/providers/ionoscloud/helpers"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
)

type ApplicationLoadBalancerGenerator struct {
Service
}

func (g *ApplicationLoadBalancerGenerator) InitResources() error {
client := g.generateClient()
cloudAPIClient := client.CloudAPIClient
resourceType := "ionoscloud_application_loadbalancer"
datacenters, err := helpers.GetAllDatacenters(*cloudAPIClient)
if err != nil {
return err
}
for _, datacenter := range datacenters {
applicationLoadBalancerResponse, _, err := cloudAPIClient.ApplicationLoadBalancersApi.DatacentersApplicationloadbalancersGet(context.TODO(), *datacenter.Id).Depth(1).Execute()
if err != nil {
return err
}
if applicationLoadBalancerResponse.Items == nil {
log.Printf(
"[WARNING] expected a response containing application load balancers but received 'nil' instead, skipping search for datacenter with ID: %v.\n",
*datacenter.Id)
continue
}
applicationLoadBalancers := *applicationLoadBalancerResponse.Items
for _, applicationLoadBalancer := range applicationLoadBalancers {
if applicationLoadBalancer.Properties == nil || applicationLoadBalancer.Properties.Name == nil {
log.Printf(
"[WARNING] 'nil' values in the response for application load balancer with ID %v, datacenter ID: %v, skipping this resource.\n",
*applicationLoadBalancer.Id,
*datacenter.Id,
)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*applicationLoadBalancer.Id,
*applicationLoadBalancer.Properties.Name+"-"+*applicationLoadBalancer.Id,
resourceType,
helpers.Ionos,
map[string]string{helpers.DcID: *datacenter.Id},
[]string{},
map[string]interface{}{}))
}
}
return nil
}
46 changes: 46 additions & 0 deletions providers/ionoscloud/backup_unit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ionoscloud

import (
"context"
"log"

"github.com/GoogleCloudPlatform/terraformer/providers/ionoscloud/helpers"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
)

type BackupUnitGenerator struct {
Service
}

func (g *BackupUnitGenerator) InitResources() error {
client := g.generateClient()
cloudAPIClient := client.CloudAPIClient
resourceType := "ionoscloud_backup_unit"

backupUnitResponse, _, err := cloudAPIClient.BackupUnitsApi.BackupunitsGet(context.TODO()).Depth(1).Execute()
if err != nil {
return err
}
if backupUnitResponse.Items == nil {
log.Printf("[WARNING] expected a response containing backup units but received 'nil' instead.")
return nil
}
backupUnits := *backupUnitResponse.Items
for _, backupUnit := range backupUnits {
if backupUnit.Properties == nil || backupUnit.Properties.Name == nil {
log.Printf(
"[WARNING] 'nil' values in the response for backup unit with ID %v, skipping this resource.\n",
*backupUnit.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*backupUnit.Id,
*backupUnit.Properties.Name+"-"+*backupUnit.Id,
resourceType,
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return nil
}
43 changes: 43 additions & 0 deletions providers/ionoscloud/datacenter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ionoscloud

import (
"log"

"github.com/GoogleCloudPlatform/terraformer/providers/ionoscloud/helpers"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
ionoscloud "github.com/ionos-cloud/sdk-go/v6"
)

type DatacenterGenerator struct {
Service
}

func (g DatacenterGenerator) createResources(datacentersList []ionoscloud.Datacenter) []terraformutils.Resource {
var resources []terraformutils.Resource
for _, datacenter := range datacentersList {
if datacenter.Properties == nil || datacenter.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for Datacenter with ID %v, skipping this resource.\n", *datacenter.Id)
continue
}
resources = append(resources, terraformutils.NewResource(
*datacenter.Id,
*datacenter.Properties.Name+"-"+*datacenter.Id,
"ionoscloud_datacenter",
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return resources
}

func (g *DatacenterGenerator) InitResources() error {
client := g.generateClient()
cloudAPIClient := client.CloudAPIClient
output, err := helpers.GetAllDatacenters(*cloudAPIClient)
if err != nil {
return err
}
g.Resources = g.createResources(output)
return nil
}
53 changes: 53 additions & 0 deletions providers/ionoscloud/dbaas_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ionoscloud

import (
"context"
"log"

"github.com/GoogleCloudPlatform/terraformer/providers/ionoscloud/helpers"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
dbaas "github.com/ionos-cloud/sdk-go-dbaas-postgres"
)

type DBaaSClusterGenerator struct {
Service
}

func (g DBaaSClusterGenerator) createResources(
clustersList []dbaas.ClusterResponse,
) []terraformutils.Resource {
var resources []terraformutils.Resource
for _, cluster := range clustersList {
if cluster.Properties == nil || cluster.Properties.DisplayName == nil {
log.Printf(
"[WARNING] 'nil' values in the response for db cluster with ID %v, skipping this resource.\n",
*cluster.Id,
)
continue
}
resources = append(resources, terraformutils.NewResource(
*cluster.Id,
*cluster.Properties.DisplayName+"-"+*cluster.Id,
"ionoscloud_pg_cluster",
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return resources
}

func (g *DBaaSClusterGenerator) InitResources() error {
client := g.generateClient()
dbaasAPIClient := client.DBaaSApiClient
output, _, err := dbaasAPIClient.ClustersApi.ClustersGet(context.TODO()).Execute()
if err != nil {
return err
}
if output.Items != nil {
g.Resources = g.createResources(*output.Items)
} else {
log.Printf("[WARNING] expected a response containing db clusters but received 'nil' instead.")
}
return nil
}
Loading