Skip to content

Commit

Permalink
Feature: add remaining IonosCloud resources (#1834)
Browse files Browse the repository at this point in the history
* doc: fix typo in documentation

* doc: add template for PRs

* fix: fix PR template

* fead: add support for Certificate Manager

* feat: implement Private CrossConnect

* fix: use proper depth for API calls

* feat: implement S3 keys

* fix: rename a variable and fix a typo in a warning message (#12)

* feat: add support for Container Registry (#11)

* feat: add support for Data Platform (#13)

* feat: add support for IONOSCLOUD shares (#14)

* feat: add support for IONOSCLOUD users (#15)

* feat: add support for CUBE and VCPU servers (#17)

* feat: add support for Container Registry Tokens (#18)

* feat: add support for ALB forwarding rules (#19)

* feat: Add support for DBaaS Mongo Clusters (#22)

* feat: add support for DNS Zones (#20)

* feat: add support for DNS Zones

* fix: Modify user agent and update documentation with info about mongo clusters

* feat: add support for DNS Records (#23)

* feat: add support for DBaaS Mongo Users (#24)

* feat: add support for DBaaS PgSQL users (#25)

* feat: add support for DBaaS PgSQL databases (#26)

* feat: add support for Logging Pipelines (#28)

* feat: add support for IP failover groups (#27)

* refactor: fix linter errors (#29)
  • Loading branch information
adeatcu-ionos committed Feb 7, 2024
1 parent 8ae2440 commit 11226f4
Show file tree
Hide file tree
Showing 30 changed files with 1,151 additions and 45 deletions.
20 changes: 19 additions & 1 deletion docs/ionoscloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,25 @@ export IONOS_TOKEN="token"
* [`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)
* [`pg_cluster`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_pgsql_cluster)
* [`pg_user`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_pgsql_user)
* [`pg_database`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_pgsql_database)
* [`mongo_cluster`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_mongo_cluster)
* [`mongo_user`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dbaas_mongo_user)
* [`certificate`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/certificate)
* [`private_crossconnect`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/private_crossconnect)
* [`s3_key`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/s3_key)
* [`container_registry`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/container_registry)
* [`dataplatform_cluster`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dataplatform_cluster)
* [`dataplatform_node_pool`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dataplatform_node_pool)
* [`share`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/share)
* [`user`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/user)
* [`container_registry_token`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/container_registry_token)
* [`application_loadbalancer_forwardingrule`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/application_loadbalancer_forwardingrule)
* [`dns_zone`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dns_zone)
* [`dns_record`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/dns_record)
* [`logging_pipeline`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/logging_pipeline)
* [`ipfailover`](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/latest/docs/resources/ipfailover)

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
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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-dbaas-mongo v1.3.1
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2
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
Expand Down Expand Up @@ -392,6 +393,12 @@ require (
)

require (
github.com/gofrs/uuid/v3 v3.1.2
github.com/ionos-cloud/sdk-go-cert-manager v1.0.0
github.com/ionos-cloud/sdk-go-container-registry v1.0.0
github.com/ionos-cloud/sdk-go-dataplatform v1.0.1
github.com/ionos-cloud/sdk-go-dns v1.1.1
github.com/ionos-cloud/sdk-go-logging v1.0.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.392
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.392
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.392
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid/v3 v3.1.2 h1:V3IBv1oU82x6YIr5txe3azVHgmOKYdyKQTowm9moBlY=
github.com/gofrs/uuid/v3 v3.1.2/go.mod h1:xPwMqoocQ1L5G6pXX5BcE7N5jlzn2o19oqAKxwZW/kI=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
Expand Down Expand Up @@ -1063,8 +1065,20 @@ 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-cert-manager v1.0.0 h1:pPIhdjTB3rjP9x3Cf6B4j8NTZ1u2v/w7/0h7GtFs/Ig=
github.com/ionos-cloud/sdk-go-cert-manager v1.0.0/go.mod h1:nFzMT0UNtNiLIuDGYj8pulHFQiVVql43oEX/eQIyr5Q=
github.com/ionos-cloud/sdk-go-container-registry v1.0.0 h1:03FKtFfHdOPZdXxRAFWgivbhmkyY4xk+R79EffoFt/4=
github.com/ionos-cloud/sdk-go-container-registry v1.0.0/go.mod h1:AtjqGZWAvd5J1rRR0wHhZ8nMrR/yJm45z8KB3p8rrvs=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.1 h1:3BeDDlHl9mQAYmgdg8EsgsXbPMDfL4pJhXzmTPHNpA0=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.1/go.mod h1:YitNqq01IAbzMr1GpXIDW1+pvhiY9eUs7/+rB9UitXE=
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1 h1:+tDoZ8IEPxYwJd6fDIpWksNJs9Zzw7Pu5A39jTew058=
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1/go.mod h1:rxOAeyAU6BTfghJibSRDdRNrKm2cIXMpSMe7JIWewJ8=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2 h1:AaKbci+kVS6/k43VwJwmXxCJ7pzj9jwuOPqO8Wd5560=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2/go.mod h1:nmJEwuRX65A5/PxwvdFW0XrV+N6WFYnMV1TiIafAwz4=
github.com/ionos-cloud/sdk-go-dns v1.1.1 h1:Qdf5mXYt9ZeRl4zZQxGrvamFkKm1X9WeARyB9/WYhKg=
github.com/ionos-cloud/sdk-go-dns v1.1.1/go.mod h1:l9gYdwtUshlBOiIi4nHn3RCX81XlV3VoNvLJrO2VfHg=
github.com/ionos-cloud/sdk-go-logging v1.0.1 h1:MB9jPoBUL3mZ+ois7kXYy67x0FopAw2aihMGdr2wu1k=
github.com/ionos-cloud/sdk-go-logging v1.0.1/go.mod h1:P2JQJpUgH3ZyfyJmv6jMwcB1NJIVVZSL+/bllhWpwc8=
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/jefferai/jsonx v1.0.1 h1:GvWkLWihoLqDG0BSP45TUQJH9qsINX50PVrFULgpc/I=
Expand Down
70 changes: 70 additions & 0 deletions providers/ionoscloud/application_load_balancer_forwarding_rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ionoscloud

import (
"context"
"log"

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

type ALBForwardingRuleGenerator struct {
Service
}

func (g *ALBForwardingRuleGenerator) InitResources() error {
client := g.generateClient()
cloudAPIClient := client.CloudAPIClient
resourceType := "ionoscloud_application_loadbalancer_forwardingrule"
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",
*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",
*applicationLoadBalancer.Id,
*datacenter.Id,
)
continue
}
albForwardingRulesResponse, _, err := cloudAPIClient.ApplicationLoadBalancersApi.DatacentersApplicationloadbalancersForwardingrulesGet(context.TODO(), *datacenter.Id, *applicationLoadBalancer.Id).Depth(1).Execute()
if err != nil {
return err
}
if albForwardingRulesResponse.Items == nil {
log.Printf("[WARNING] expected a response containing ALB forwarding rules but received 'nil' instead, skipping search for ALB with ID: %v, datacenter ID: %v", *applicationLoadBalancer.Id, *datacenter.Id)
continue
}
albForwardingRules := *albForwardingRulesResponse.Items
for _, albForwardingRule := range albForwardingRules {
if albForwardingRule.Properties == nil || albForwardingRule.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for ALB forwarding rule with ID: %v, ALB ID: %v, datacenter ID: %v, skipping this resource", *albForwardingRule.Id, *applicationLoadBalancer.Id, *datacenter.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*albForwardingRule.Id,
*albForwardingRule.Properties.Name+"-"+*albForwardingRule.Id,
resourceType,
helpers.Ionos,
map[string]string{"application_loadbalancer_id": *applicationLoadBalancer.Id, helpers.DcID: *datacenter.Id},
[]string{},
map[string]interface{}{}))
}
}
}
return nil
}
44 changes: 44 additions & 0 deletions providers/ionoscloud/certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ionoscloud

import (
"context"
"log"

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

type CertificateGenerator struct {
Service
}

func (g *CertificateGenerator) InitResources() error {
client := g.generateClient()
certManagerAPIClient := client.CertificateManagerAPIClient
resourceType := "ionoscloud_certificate"

response, _, err := certManagerAPIClient.CertificatesApi.CertificatesGet(context.TODO()).Execute()
if err != nil {
return err
}
if response.Items == nil {
log.Printf("[WARNING] expected a response containing certificates but received 'nil' instead.")
return nil
}
certificates := *response.Items
for _, certificate := range certificates {
if certificate.Properties == nil || certificate.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for the certificate with ID %v, skipping this resource.", *certificate.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*certificate.Id,
*certificate.Properties.Name+"-"+*certificate.Id,
resourceType,
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return nil
}
44 changes: 44 additions & 0 deletions providers/ionoscloud/container_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ionoscloud

import (
"context"
"log"

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

type ContainerRegistryGenerator struct {
Service
}

func (g *ContainerRegistryGenerator) InitResources() error {
client := g.generateClient()
containerRegistryAPIClient := client.ContainerRegistryAPIClient
resourceType := "ionoscloud_container_registry"

response, _, err := containerRegistryAPIClient.RegistriesApi.RegistriesGet(context.TODO()).Execute()
if err != nil {
return err
}
if response.Items == nil {
log.Printf("[WARNING] expected a response containing registries but received 'nil' instead.")
return nil
}
registries := *response.Items
for _, registry := range registries {
if registry.Properties == nil || registry.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for the registry with ID %v, skipping this resource.", *registry.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*registry.Id,
*registry.Properties.Name+"-"+*registry.Id,
resourceType,
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return nil
}
55 changes: 55 additions & 0 deletions providers/ionoscloud/container_registry_token.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 ContainerRegistryTokenGenerator struct {
Service
}

func (g *ContainerRegistryTokenGenerator) InitResources() error {
client := g.generateClient()
crClient := client.ContainerRegistryAPIClient
resourceType := "ionoscloud_container_registry_token"

registriesResponse, _, err := crClient.RegistriesApi.RegistriesGet(context.TODO()).Execute()
if err != nil {
return err
}
if registriesResponse.Items == nil {
log.Printf("[WARNING] expected a response containing registries but received 'nil' instead")
return nil
}
registries := *registriesResponse.Items
for _, registry := range registries {
tokensResponse, _, err := crClient.TokensApi.RegistriesTokensGet(context.TODO(), *registry.Id).Execute()
if err != nil {
return err
}
if tokensResponse.Items == nil {
log.Printf("[WARNING] expected a response containing container registry tokens, but received 'nil' instead")
return nil
}
crTokens := *tokensResponse.Items
for _, crToken := range crTokens {
if crToken.Properties == nil || crToken.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for the container registry token with ID: %v, skipping this resource", *crToken.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*crToken.Id,
*crToken.Properties.Name+"-"+*crToken.Id,
resourceType,
helpers.Ionos,
map[string]string{"registry_id": *registry.Id},
[]string{},
map[string]interface{}{}))
}
}
return nil
}
44 changes: 44 additions & 0 deletions providers/ionoscloud/dataplatform_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ionoscloud

import (
"context"
"log"

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

type DataPlatformClusterGenerator struct {
Service
}

func (g *DataPlatformClusterGenerator) InitResources() error {
client := g.generateClient()
dataPlatformClient := client.DataPlatformAPIClient
resourceType := "ionoscloud_dataplatform_cluster"

response, _, err := dataPlatformClient.DataPlatformClusterApi.ClustersGet(context.TODO()).Execute()
if err != nil {
return err
}
if response.Items == nil {
log.Printf("[WARNING] expected a response containing data platform clusters, but received 'nil' instead.")
return nil
}
clusters := *response.Items
for _, cluster := range clusters {
if cluster.Properties == nil || cluster.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for data platform cluster with ID %v, skipping this resource.", *cluster.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*cluster.Id,
*cluster.Properties.Name+"-"+*cluster.Id,
resourceType,
helpers.Ionos,
map[string]string{},
[]string{},
map[string]interface{}{}))
}
return nil
}
55 changes: 55 additions & 0 deletions providers/ionoscloud/dataplatform_node_pool.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 DataPlatformNodePoolGenerator struct {
Service
}

func (g *DataPlatformNodePoolGenerator) InitResources() error {
client := g.generateClient()
dataPlatformClient := client.DataPlatformAPIClient
resourceType := "ionoscloud_dataplatform_node_pool"

dpClusters, _, err := dataPlatformClient.DataPlatformClusterApi.ClustersGet(context.TODO()).Execute()
if err != nil {
return err
}
if dpClusters.Items == nil {
log.Printf("[WARNING] expected a response containing data platform clusters but received 'nil' instead.")
return nil
}
for _, dpCluster := range *dpClusters.Items {
dpNodePools, _, err := dataPlatformClient.DataPlatformNodePoolApi.ClustersNodepoolsGet(context.TODO(), *dpCluster.Id).Execute()
if err != nil {
return err
}
if dpNodePools.Items == nil {
log.Printf("[WARNING] expected a response containing data platform node pools but received 'nil' instead, skipping search for data platform cluster with ID: %v", *dpCluster.Id)
continue
}
for _, dpNodePool := range *dpNodePools.Items {
if dpNodePool.Properties == nil || dpNodePool.Properties.Name == nil {
log.Printf("[WARNING] 'nil' values in the response for data platform node pool with ID %v, cluster ID: %v, skipping this resource",
*dpNodePool.Id,
*dpCluster.Id)
continue
}
g.Resources = append(g.Resources, terraformutils.NewResource(
*dpNodePool.Id,
*dpNodePool.Properties.Name+"-"+*dpNodePool.Id,
resourceType,
helpers.Ionos,
map[string]string{helpers.ClusterID: *dpCluster.Id},
[]string{},
map[string]interface{}{}))
}
}
return nil
}
Loading

0 comments on commit 11226f4

Please sign in to comment.