Git Product home page Git Product logo

terraform-provider-clevercloud's Introduction

Terraform Clever Cloud Provider

The Clever Cloud Provider allows Terraform to manage Clever Cloud resources.

Build provider

Run the following command to build the provider

$ go build -o terraform-provider-clevercloud

Test sample configuration

First, build and install the provider.

$ make install

Then, navigate to the examples directory.

$ cd examples

Run the following command to initialize the workspace and apply the sample configuration.

$ terraform init && terraform apply

terraform-provider-clevercloud's People

Contributors

clevercloud-ci avatar davlgd avatar juwit avatar miton18 avatar thecrabe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

terraform-provider-clevercloud's Issues

Application

Implement Application Data Source with all its sub-resources

options : redirect_https & sticky_sessions not working

When I deploy a node/PG application through the provider with some options, they are not applied.

  • Terraform version : 1.4.5
  • Provider version : 0.0.10

Terraform Configuration Files

provider "clevercloud" {
  organisation = var.organisation
}

resource "clevercloud_postgresql" "terraformTestPG" {
  name = "terraformTestPG"
  plan = "xxs_sml"
  region = "scw"
}

resource "clevercloud_nodejs" "terraformTestApp" {
  name = "terraformTestApp"
  region = "scw"
  min_instance_count = 1
  max_instance_count = 4
  smallest_flavor = "nano"
  biggest_flavor = "XS"
  redirect_https = true
  sticky_sessions = true
  additional_vhosts = ["demotf.dauh.fr"]
  dependencies = [clevercloud_postgresql.terraformTestPG.id]
  deployment {repository = "https://github.com/CleverCloud/expressjs-postgresql-example"}
}

Expected Behavior

Enabling redirect_https or sticky_sessions should activate these options in the deployed application.

Actual Behavior

When set to true, redirect_https or sticky_sessions stay disabled in the deployed application.

Steps to Reproduce

  • Use this config in a main.tf file
  • terraform apply
  • Look at the Clever Cloud Console nodejs app in the Information panel
  • HTTPS/Sticky options are not activated

Updating an application raises an error

Hello,

we encountered an error while trying to update an app using terraform:

Terraform Version

➜  ~ terraform -v
Terraform v1.6.6
on darwin_arm64

Affected Resource(s)

  • clevercloud_nodejs
  • clevercloud_java_war
  • (probably all the application resources)

Terraform Configuration Files

resource "clevercloud_java_war" "myapp_java" {
    name = "tf-myapp"
    region = "par"
    min_instance_count = 1
    max_instance_count = 2
    smallest_flavor = "XS"
    biggest_flavor = "M"
}

Expected Behavior

when I change biggest_flavor = "M" for biggest_flavor = "S" it should update the vertical scaling settings of the application

Actual Behavior

it raises an error

➜  terraform apply
clevercloud_java_war.myapp_java: Refreshing state... [id=XXXXXXX]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # clevercloud_java_war.myapp_java will be updated in-place
  ~ resource "clevercloud_java_war" "myapp_java" {
      ~ biggest_flavor     = "M" -> "XS"
      ~ deploy_url         = "git+ssh://[email protected]/XXXXX.git" -> (known after apply)
      ~ id                 = "XXXXXX" -> (known after apply)
        name               = "tf-myapp"
      ~ vhost              = "XXXXXX.cleverapps.io" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

clevercloud_java_war.myapp_java: Modifying... [id=XXXXXX]
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to clevercloud_java_war.myapp_java, provider "provider[\"registry.terraform.io/clevercloud/clevercloud\"]" produced an
│ unexpected new value: .biggest_flavor: was cty.StringVal("XS"), but now cty.StringVal("M").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

Thanks

block helper

We can make an helper to build some tf blocks, it will ease tests

something like

// block package


block.
  Provider("clevercloud",
    block.String("organisation", "org_xxx")
  ).
  String()

// or

block.
  Provider("clevercloud").
  WithString("organisation", "org_xxx").
  String()



// with the output
provider "clevercloud" {
	organisation = "org_xxx"
}

Race condition on Application resource

I got a panic when:
Trying to declare a "clevercloud_application" resource which does not exists yet.
instance seems nil and previous error check too.

defaultFlavorName := instance.DefaultFlavor.Name
2021-12-06T17:17:13.216+0100 [WARN]  Provider "local/clevercloud/clevercloud" produced an invalid plan for clevercloud_application.poke-api, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .min_instances: planned value cty.NumberIntVal(1) for a non-computed attribute
      - .deploy_type: planned value cty.StringVal("git") for a non-computed attribute
clevercloud_application.poke-api: Creating...
2021-12-06T17:17:13.217+0100 [INFO]  Starting apply for clevercloud_application.poke-api
2021-12-06T17:17:13.217+0100 [DEBUG] clevercloud_application.poke-api: applying the planned Create change
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: PANIC: runtime error: invalid memory address or nil pointer dereference
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xac7c1a]
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: 
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: goroutine 58 [running]:
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/clevercloud/terraform-provider-clevercloud/clevercloud.resourceApplicationCreate({0xd435f8, 0xc000480280}, 0xc0002037b8, {0xba66a0, 0xc00049fae0})
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/clevercloud/resource_application.go:173 +0x15a
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0003a2000, {0xd435f8, 0xc000480280}, 0x2, {0xba66a0, 0xc00049fae0})
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:330 +0x12e
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003a2000, {0xd435f8, 0xc000480280}, 0xc00028a230, 0xc0002b6320, {0xba66a0, 0xc00049fae0})
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:456 +0x871
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000338078, {0xd435f8, 0xc000480280}, 0xc00028e2d0)
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/grpc_provider.go:955 +0x9aa
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc000308da0, {0xd436a0, 0xc000288000}, 0x0)
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/server/server.go:332 +0x6c
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xc059c0, 0xc000308da0}, {0xd436a0, 0xc000288000}, 0xc000526180, 0x0)
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00032c700, {0xd50290, 0xc0001f2480}, 0xc000156200, 0xc0003f27b0, 0x1221e40, 0x0)
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/google.golang.org/grpc/server.go:1194 +0xc8f
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: google.golang.org/grpc.(*Server).handleStream(0xc00032c700, {0xd50290, 0xc0001f2480}, 0xc000156200, 0x0)
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/google.golang.org/grpc/server.go:1517 +0xa2a
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: google.golang.org/grpc.(*Server).serveStreams.func1.2()
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/google.golang.org/grpc/server.go:859 +0x98
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud: created by google.golang.org/grpc.(*Server).serveStreams.func1
2021-12-06T17:17:13.404+0100 [DEBUG] provider.terraform-provider-clevercloud:   /home/miton/code/go/terraform-provider-clevercloud/vendor/google.golang.org/grpc/server.go:857 +0x294
2021-12-06T17:17:13.405+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/local/clevercloud/clevercloud/0.1.0/linux_amd64/terraform-provider-clevercloud pid=3896 error="exit status 2"
2021-12-06T17:17:13.406+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-12-06T17:17:13.406+0100 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = transport is closing"
╷
│ Error: Plugin did not respond
│ 
│   with clevercloud_application.poke-api,
│   on poke.tf line 27, in resource "clevercloud_application" "poke-api":
│   27: resource "clevercloud_application" "poke-api" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.

mongodb adddon produce module crash

Hello,

seems that mongodb resource is broken since not so long ago,
it produce a go panic error on apply.

Have a good day.

Terraform Version

Terraform v1.6.4

Affected Resource(s)

  • mongodb

Terraform Configuration Files

db = {
  staging = {
    "plan"   = "XS_SML"
    "name"   = "xxxxxxxxxxxxxxxxxx-pg-staging"
    "type"   = "md"
    "region" = "par"
  }
  production = {
    "plan"   = "XS_SML"
    "name"   = "xxxxxxxxxxxxxxxxxx-pg-production"
    "region" = "par"
    "type"   = "md"
  }
}
resource "clevercloud_mongodb" "mongodb" {
  count  = var.db[local.env].type == "md" ? 1 : 0
  name   = var.db[local.env].name
  plan   = var.db[local.env].plan
  region = var.db[local.env].region
}

Panic Output


Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # clevercloud_mongodb.mongodb[0] will be created
  + resource "clevercloud_mongodb" "mongodb" {
      + creation_date = (known after apply)
      + host          = (known after apply)
      + id            = (known after apply)
      + name          = "klanikdotcom-pg-staging"
      + password      = (known after apply)
      + plan          = "XS_SML"
      + port          = (known after apply)
      + region        = "par"
      + user          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
clevercloud_mongodb.mongodb[0]: Creating...
╷
│ Warning: Resource targeting is in effect
│
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.
│
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an error message.
╵
╷
│ Warning: Applied changes may be incomplete
│
│ The plan was created with the -target option in effect, so some changes requested in the configuration may have been ignored and the output values may not be fully updated. Run the following command to verify that no other changes are pending:
│     terraform plan
│ 	
│ Note that the -target option is not suitable for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an error message.
╵
╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-clevercloud_v0.4.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xcca57e]

goroutine 58 [running]:
go.clever-cloud.com/terraform-provider/pkg/resources/mongodb.(*ResourceMongoDB).Create(0xc00056d3b0, {0x1088448, 0xc0006288d0}, {{{{0x108e758, 0xc000629350}, {0xdb8cc0, 0xc000629200}}, {0x1090718, 0xc0003b2280}}, {{{0x108e758, ...}, ...}, ...}, ...}, ...)
	go.clever-cloud.com/terraform-provider/pkg/resources/mongodb/crud.go:52 +0x21e
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0xc000173ba0, {0x1088448, 0xc0006288d0}, 0xc00068f580, 0xc00068f520)
	github.com/hashicorp/[email protected]/internal/fwserver/server_createresource.go:101 +0x578
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0xc00068f6d8?, {0x1088448, 0xc0006288d0}, 0xc00055f720, 0xc00068f6d8)
	github.com/hashicorp/[email protected]/internal/fwserver/server_applyresourcechange.go:57 +0x4a5
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ApplyResourceChange(0xc000173ba0, {0x1088448?, 0xc0006287b0?}, 0xc00055f680)
	github.com/hashicorp/[email protected]/internal/proto6server/server_applyresourcechange.go:55 +0x3e5
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc000234be0, {0x1088448?, 0xc000579dd0?}, 0xc0003696c0)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:846 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0xed2200?, 0xc000234be0}, {0x1088448, 0xc000579dd0}, 0xc00014f100, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00014b600, {0x1088448, 0xc000579d40}, {0x108f328, 0xc00048a1a0}, 0xc00056fe60, 0xc00032a4e0, 0x1730938, 0x0)
	google.golang.org/[email protected]/server.go:1386 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc00014b600, {0x108f328, 0xc00048a1a0}, 0xc00056fe60)
	google.golang.org/[email protected]/server.go:1797 +0x100c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1027 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 36
	google.golang.org/[email protected]/server.go:1038 +0x135

Error: The terraform-provider-clevercloud_v0.4.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected Behavior

Should create a DB

Actual Behavior

Crash like a plane with no wings

Steps to Reproduce

  1. terraform apply

autoscalabilty : min_instance_count not applied

When I deploy a node/PG application through the provider with autoscalability, minimum instance parameter is not applied.

  • Terraform version : 1.4.5
  • Provider version : 0.0.9

Terraform Configuration Files

provider "clevercloud" {
  organisation = var.organisation
}

resource "clevercloud_postgresql" "terraformTestPG" {
  name = "terraformTestPG"
  plan = "xxs_sml"
  region = "scw"
}

resource "clevercloud_nodejs" "terraformTestApp" {
  name = "terraformTestApp"
  region = "scw"
  min_instance_count = 1
  max_instance_count = 4
  smallest_flavor = "nano"
  biggest_flavor = "XS"
  dependencies = [clevercloud_postgresql.terraformTestPG.id]
  deployment {repository = "https://github.com/CleverCloud/expressjs-postgresql-example"}
}

Expected Behavior

The nodejs app should be created with a 1 > 4 instances autoscalabilty in the CC Console

Actual Behavior

With this configuration file, the nodejs app is created with 4 > 4 instances autoscalabilty :

image

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Use this config in a main.tf file
  2. terraform apply
  3. Look at the Clever Cloud Console nodejs app in the Scalability panel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.