-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
604fd08
commit 6e2cbc3
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters