-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
8 changed files
with
129 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package credentials | ||
|
||
const ( | ||
resourceName = "cyral_sidecar_credentials" | ||
) |
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,38 @@ | ||
package credentials | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type CreateSidecarCredentialsRequest struct { | ||
SidecarID string `json:"sidecarId"` | ||
} | ||
|
||
func (r *CreateSidecarCredentialsRequest) ReadFromSchema(d *schema.ResourceData) error { | ||
r.SidecarID = d.Get("sidecar_id").(string) | ||
return nil | ||
} | ||
|
||
type SidecarCredentialsData struct { | ||
SidecarID string `json:"sidecarId"` | ||
ClientID string `json:"clientId"` | ||
ClientSecret string `json:"clientSecret"` | ||
} | ||
|
||
func (r *SidecarCredentialsData) WriteToSchema(d *schema.ResourceData) error { | ||
if err := d.Set("client_id", r.ClientID); err != nil { | ||
return fmt.Errorf("error setting 'client_id' field: %w", err) | ||
} | ||
if r.ClientSecret != "" { | ||
if err := d.Set("client_secret", r.ClientSecret); err != nil { | ||
return fmt.Errorf("error setting 'client_secret' field: %w", err) | ||
} | ||
} | ||
if err := d.Set("sidecar_id", r.SidecarID); err != nil { | ||
return fmt.Errorf("error setting 'sidecar_id' field: %w", err) | ||
} | ||
d.SetId(r.ClientID) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package credentials | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cyralinc/terraform-provider-cyral/cyral/client" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/core" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/core/types/resourcetype" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
var resourceContextHandler = core.DefaultContextHandler{ | ||
ResourceName: resourceName, | ||
ResourceType: resourcetype.Resource, | ||
SchemaReaderFactory: func() core.SchemaReader { return &CreateSidecarCredentialsRequest{} }, | ||
SchemaWriterFactoryGetMethod: func(_ *schema.ResourceData) core.SchemaWriter { return &SidecarCredentialsData{} }, | ||
SchemaWriterFactoryPostMethod: func(_ *schema.ResourceData) core.SchemaWriter { return &SidecarCredentialsData{} }, | ||
BaseURLFactory: func(d *schema.ResourceData, c *client.Client) string { | ||
return fmt.Sprintf("https://%s/v1/users/sidecarAccounts", c.ControlPlane) | ||
}, | ||
} | ||
|
||
func resourceSchema() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Create new [credentials for Cyral sidecar](https://cyral.com/docs/sidecars/sidecar-manage/#rotate-the-client-secret-for-a-sidecar).", | ||
CreateContext: resourceContextHandler.CreateContext(), | ||
ReadContext: resourceContextHandler.ReadContext(), | ||
DeleteContext: resourceContextHandler.DeleteContext(), | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Description: "Same as `client_id`.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sidecar_id": { | ||
Description: "ID of the sidecar to create new credentials.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"client_id": { | ||
Description: "Sidecar client ID.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"client_secret": { | ||
Description: "Sidecar client secret.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
} | ||
} |
128 changes: 0 additions & 128 deletions
128
cyral/internal/sidecar/credentials/resource_cyral_sidecar_credentials.go
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,26 @@ | ||
package credentials | ||
|
||
import ( | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/core" | ||
) | ||
|
||
type packageSchema struct { | ||
} | ||
|
||
func (p *packageSchema) Name() string { | ||
return "credentials" | ||
} | ||
|
||
func (p *packageSchema) Schemas() []*core.SchemaDescriptor { | ||
return []*core.SchemaDescriptor{ | ||
{ | ||
Name: resourceName, | ||
Type: core.ResourceSchemaType, | ||
Schema: resourceSchema, | ||
}, | ||
} | ||
} | ||
|
||
func PackageSchema() core.PackageSchema { | ||
return &packageSchema{} | ||
} |
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