-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feat: add support for 'move environment' backend #939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,34 @@ package client | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type ConfigurationVariableType int | ||
|
||
func (c *ConfigurationVariableType) ReadResourceData(fieldName string, d *schema.ResourceData) error { | ||
val := d.Get(fieldName).(string) | ||
intVal, ok := VariableTypes[val] | ||
if !ok { | ||
return fmt.Errorf("unknown configuration variable type %s", val) | ||
|
||
intVal, err := GetConfigurationVariableType(val) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*c = intVal | ||
|
||
return nil | ||
} | ||
|
||
func (c *ConfigurationVariableType) WriteResourceData(fieldName string, d *schema.ResourceData) error { | ||
val := *c | ||
valStr := "" | ||
if val == 0 { | ||
var valStr string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated - working on linting fixes as I go... |
||
|
||
switch val := *c; val { | ||
case 0: | ||
valStr = "environment" | ||
} else if val == 1 { | ||
case 1: | ||
valStr = "terraform" | ||
} else { | ||
default: | ||
return fmt.Errorf("unknown configuration variable type %d", val) | ||
} | ||
|
||
|
@@ -40,11 +44,6 @@ const ( | |
|
||
type ConfigurationChanges []ConfigurationVariable | ||
|
||
var VariableTypes = map[string]ConfigurationVariableType{ | ||
"terraform": ConfigurationVariableTypeTerraform, | ||
"environment": ConfigurationVariableTypeEnvironment, | ||
} | ||
|
||
type TTL struct { | ||
Type TTLType `json:"type"` | ||
Value string `json:"value,omitempty"` | ||
|
@@ -159,6 +158,21 @@ type EnvironmentCreateWithoutTemplate struct { | |
TemplateCreate TemplateCreatePayload | ||
} | ||
|
||
type EnvironmentMoveRequest struct { | ||
ProjectId string `json:"projectId"` | ||
} | ||
|
||
func GetConfigurationVariableType(variableType string) (ConfigurationVariableType, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated - working on linting fixes as I go... |
||
switch variableType { | ||
case "terraform": | ||
return ConfigurationVariableTypeTerraform, nil | ||
case "environment": | ||
return ConfigurationVariableTypeEnvironment, nil | ||
default: | ||
return 0, fmt.Errorf("unknown configuration variable type %s", variableType) | ||
} | ||
} | ||
|
||
// The custom marshalJSON is used to return a flat JSON. | ||
func (create EnvironmentCreateWithoutTemplate) MarshalJSON() ([]byte, error) { | ||
// 1. Marshal to JSON both structs. | ||
|
@@ -173,9 +187,11 @@ func (create EnvironmentCreateWithoutTemplate) MarshalJSON() ([]byte, error) { | |
|
||
// 2. Unmarshal both JSON byte arrays to two maps. | ||
var ecm, tcm map[string]interface{} | ||
|
||
if err := json.Unmarshal(ecb, &ecm); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := json.Unmarshal(tcb, &tcm); err != nil { | ||
return nil, err | ||
} | ||
|
@@ -254,8 +270,9 @@ func (client *ApiClient) EnvironmentCreateWithoutTemplate(payload EnvironmentCre | |
|
||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return result, nil | ||
return result, err | ||
} | ||
|
||
payload.TemplateCreate.OrganizationId = organizationId | ||
|
||
if err := client.http.Post("/environments/without-template", payload, &result); err != nil { | ||
|
@@ -311,3 +328,11 @@ func (client *ApiClient) EnvironmentDeploy(id string, payload DeployRequest) (En | |
} | ||
return result, nil | ||
} | ||
|
||
func (client *ApiClient) EnvironmentMove(id string, projectId string) error { | ||
payload := &EnvironmentMoveRequest{ | ||
ProjectId: projectId, | ||
} | ||
|
||
return client.http.Post("/environments/"+id+"/move", payload, nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated - working on linting fixes as I go...