Skip to content

Commit

Permalink
Added schema registry resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bisih-darko-micic authored and Mongey committed Nov 8, 2020
1 parent 604fd08 commit 6e2cbc3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ resource "confluentcloud_kafka_cluster" "test" {
environment_id = confluentcloud_environment.environment.id
}
resource "confluentcloud_schema_registry" "test" {
environment_id = confluentcloud_environment.environment.id
service_provider = "aws"
region = "EU"
# Requires at least one kafka cluster to enable
# schema registry in the environment.
depends_on = [confluentcloud_kafka_cluster.test]
}
resource "confluentcloud_api_key" "provider_test" {
cluster_id = confluentcloud_kafka_cluster.test.id
environment_id = confluentcloud_environment.environment.id
Expand Down
2 changes: 2 additions & 0 deletions ccloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func Provider() terraform.ResourceProvider {
"confluentcloud_kafka_cluster": kafkaClusterResource(),
"confluentcloud_api_key": apiKeyResource(),
"confluentcloud_environment": environmentResource(),
"confluentcloud_schema_registry": schemaRegistryResource(),
"confluentcloud_service_account": serviceAccountResource(),
},
}
}


func providerConfigure(d *schema.ResourceData) (interface{}, error) {
log.Printf("[INFO] Initializing ConfluentCloud client")
username := d.Get("username").(string)
Expand Down
90 changes: 90 additions & 0 deletions ccloud/resource_schema_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ccloud

import (
"log"

ccloud "github.com/cgroschupp/go-client-confluent-cloud/confluentcloud"
"github.com/hashicorp/terraform/helper/schema"
)

func schemaRegistryResource() *schema.Resource {
return &schema.Resource{
Create: schemaRegistryCreate,
Read: schemaRegistryRead,
Delete: schemaRegistryDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"environment_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Environment ID",
},
"region": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "where",
},
"service_provider": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Cloud provider",
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func schemaRegistryCreate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*ccloud.Client)

environment := d.Get("environment_id").(string)
region := d.Get("region").(string)
service_provider := d.Get("service_provider").(string)

log.Printf("[INFO] Creating Schema Registry %s", environment)

reg, err := c.CreateSchemaRegistry(environment, region, service_provider)
if err != nil {
return err
}

d.SetId(reg.Name + " " + environment)
err = d.Set("endpoint", reg.Endpoint)
if err != nil {
return err
}

return nil
}

func schemaRegistryRead(d *schema.ResourceData, meta interface{}) error {
c := meta.(*ccloud.Client)

environment := d.Get("environment_id").(string)
log.Printf("[INFO] Reading Schema Registry %s", environment)

env, err := c.GetSchemaRegistry(environment)
if err != nil {
return err
}

err = d.Set("environment_id", environment)
if err != nil {
err = d.Set("endpoint", env.Endpoint)
}

return err
}

func schemaRegistryDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Schema registry cannot be deleted: %s", d.Id())
return nil
}
9 changes: 9 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ resource "confluentcloud_kafka_cluster" "test" {
storage = 5000
}

resource "confluentcloud_schema_registry" "test" {
environment_id = confluentcloud_environment.environment.id
service_provider = "aws"
region = "EU"

depends_on = [confluentcloud_kafka_cluster.test]

}

resource "confluentcloud_api_key" "provider_test" {
cluster_id = confluentcloud_kafka_cluster.test.id
environment_id = confluentcloud_environment.environment.id
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Mongey/terraform-provider-confluentcloud
go 1.12

require (
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201027120443-3f6a9405b3a7
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201105075001-2e15b5846d7e
github.com/go-resty/resty/v2 v2.2.0 // indirect
github.com/hashicorp/terraform v0.12.1
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2mtRGSCPsat1kze3CUtvJN3/jTXlp29k=
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201027120443-3f6a9405b3a7 h1:sakYkbNlsrF4tVwlMGiz9Wb5cOvy56SO32WudPN6Il8=
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201027120443-3f6a9405b3a7/go.mod h1:4qz2Pftxeus+mcGJkiysWrDwf/uQL1+jEI/Yu5BpS60=
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201105075001-2e15b5846d7e h1:BJ8iiXxVgxGllpGTih3FP7FtMOvXhKryqF3J3dcW1b8=
github.com/cgroschupp/go-client-confluent-cloud v0.0.0-20201105075001-2e15b5846d7e/go.mod h1:4qz2Pftxeus+mcGJkiysWrDwf/uQL1+jEI/Yu5BpS60=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20161106042343-c914be64f07d/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down

0 comments on commit 6e2cbc3

Please sign in to comment.