Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-9847: Add service_configs field to sidecar resource #437

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM hashicorp/terraform:1.3.9 as terraform
FROM hashicorp/terraform:1.5.5 as terraform

FROM golang:1.19.6-alpine3.17 AS build
FROM golang:1.21.0-alpine3.17 AS build
WORKDIR /go/src/cyral
COPY main.go go.mod go.sum ./
COPY client/ client/
Expand All @@ -12,7 +12,7 @@ RUN gofmt -w . \
&& GOOS=darwin GOARCH=amd64 go build -o out/darwin_amd64/terraform-provider-cyral . \
&& GOOS=linux GOARCH=amd64 go build -o out/linux_amd64/terraform-provider-cyral .

FROM alpine:3.18.2 as output
FROM alpine:3.18.3 as output
ARG VERSION
RUN mkdir -p /root/.terraform.d/plugins/local/terraform/cyral/${VERSION:?You must set the VERSION build argument}
COPY --from=build /go/src/cyral/out/ /root/.terraform.d/plugins/local/terraform/cyral/${VERSION}
Expand Down
84 changes: 84 additions & 0 deletions cyral/model_sidecar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package cyral

type CreateSidecarResponse struct {
ID string `json:"ID"`
}

type SidecarData struct {
ID string `json:"id"`
Name string `json:"name"`
Labels []string `json:"labels"`
SidecarProperties *SidecarProperties `json:"properties"`
ServiceConfigs SidecarServiceConfigs `json:"services"`
UserEndpoint string `json:"userEndpoint"`
CertificateBundleSecrets CertificateBundleSecrets `json:"certificateBundleSecrets,omitempty"`
}

type SidecarProperties struct {
DeploymentMethod string `json:"deploymentMethod"`
LogIntegrationID string `json:"logIntegrationID,omitempty"`
DiagnosticLogIntegrationID string `json:"diagnosticLogIntegrationID,omitempty"`
}

func NewSidecarProperties(deploymentMethod, activityLogIntegrationID, diagnosticLogIntegrationID string) *SidecarProperties {
return &SidecarProperties{
DeploymentMethod: deploymentMethod,
LogIntegrationID: activityLogIntegrationID,
DiagnosticLogIntegrationID: diagnosticLogIntegrationID,
}
}

type SidecarServiceConfigs map[string]map[string]string

func (serviceConfigs *SidecarServiceConfigs) SidecarServiceConfigsAsInterfaceList() []any {
if serviceConfigs == nil {
return nil
}
serviceConfigsInterfaceList := []any{}
for serviceName, serviceConfig := range *serviceConfigs {
serviceConfigMap := map[string]any{
"service_name": serviceName,
"config": serviceConfig,
}
serviceConfigsInterfaceList = append(serviceConfigsInterfaceList, serviceConfigMap)
}
return serviceConfigsInterfaceList
}

func (serviceConfigs *SidecarServiceConfigs) getBypassMode() string {
if serviceConfigs != nil {
if dispatcherConfigs, ok := (*serviceConfigs)["dispatcher"]; ok {
if bypassMode, ok := dispatcherConfigs["bypass"]; ok {
return bypassMode
}
}
}
return ""
}

func getSidecarServiceConfigsDefault() SidecarServiceConfigs {
return SidecarServiceConfigs{
"certificate-manager": nil,
"dispatcher": {
"bypass": "failover",
},
"oracle-wire": {
"command-queue-size": "10",
"command-queue-timeout-ms": "200",
},
"pg-wire": {
"memory-budget-enabled": "false",
"memory-budget-per-connection": "8388608",
"memory-budget-request-factor": "512",
"memory-budget-response-factor": "2",
},
}
}

type CertificateBundleSecrets map[string]*CertificateBundleSecret

type CertificateBundleSecret struct {
Engine string `json:"engine,omitempty"`
SecretId string `json:"secretId,omitempty"`
Type string `json:"type,omitempty"`
}
20 changes: 10 additions & 10 deletions cyral/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

const (
create = OperationType("create")
read = OperationType("read")
update = OperationType("update")
delete = OperationType("delete")
CREATE = OperationType("create")
READ = OperationType("read")
UPDATE = OperationType("update")
DELETE = OperationType("delete")
)

type OperationType string
Expand Down Expand Up @@ -56,11 +56,11 @@ func CreateResource(createConfig, readConfig ResourceOperationConfig) schema.Cre
return HandleRequests(
[]ResourceOperation{
{
Type: create,
Type: CREATE,
Config: createConfig,
},
{
Type: read,
Type: READ,
Config: readConfig,
},
},
Expand All @@ -71,7 +71,7 @@ func ReadResource(readConfig ResourceOperationConfig) schema.ReadContextFunc {
return HandleRequests(
[]ResourceOperation{
{
Type: read,
Type: READ,
Config: readConfig,
},
},
Expand All @@ -82,11 +82,11 @@ func UpdateResource(updateConfig, readConfig ResourceOperationConfig) schema.Upd
return HandleRequests(
[]ResourceOperation{
{
Type: update,
Type: UPDATE,
Config: updateConfig,
},
{
Type: read,
Type: READ,
Config: readConfig,
},
},
Expand All @@ -97,7 +97,7 @@ func DeleteResource(deleteConfig ResourceOperationConfig) schema.DeleteContextFu
return HandleRequests(
[]ResourceOperation{
{
Type: delete,
Type: DELETE,
Config: deleteConfig,
},
},
Expand Down
6 changes: 3 additions & 3 deletions cyral/resource_cyral_integration_idp_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func resourceIntegrationIdPSAML() *schema.Resource {
CreateContext: CRUDResources(
[]ResourceOperation{
{
Type: create,
Type: CREATE,
Config: CreateGenericSAMLConfig(),
},
{
Type: read,
Type: READ,
Config: ReadGenericSAMLConfig(),
},
{
Type: create,
Type: CREATE,
Config: CreateIdPConfig(),
},
},
Expand Down
Loading