-
Notifications
You must be signed in to change notification settings - Fork 14
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 subenvironments #571
Conversation
@@ -348,6 +348,29 @@ func setEnvironmentSchema(d *schema.ResourceData, environment client.Environment | |||
d.Set("approve_plan_automatically", !*environment.RequiresApproval) | |||
} | |||
|
|||
if environment.LatestDeploymentLog.WorkflowFile != nil && len(environment.LatestDeploymentLog.WorkflowFile.Environments) > 0 { |
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.
This is for setting sub environments ids.
(This data is only available in the response).
if len(subEnvironments) > 0 { | ||
deployPayload.SubEnvironments = make(map[string]client.SubEnvironment) | ||
|
||
for _, subEnvironment := range subEnvironments { |
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.
Sets the sub environments in the create request.
@@ -1532,3 +1532,123 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) { | |||
}) | |||
|
|||
} | |||
|
|||
func TestUnitEnvironmentWithoutSubEnvironment(t *testing.T) { |
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.
The unit test will be expanded after the rest is implemented.
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.
what do you mean by expanded
?
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.
Update operation in unit test.
@@ -348,6 +348,29 @@ func setEnvironmentSchema(d *schema.ResourceData, environment client.Environment | |||
d.Set("approve_plan_automatically", !*environment.RequiresApproval) | |||
} | |||
|
|||
if environment.LatestDeploymentLog.WorkflowFile != nil && len(environment.LatestDeploymentLog.WorkflowFile.Environments) > 0 { | |||
iSubEnvironments, ok := d.GetOk("sub_environment_configuration") |
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.
This is the sub environments we define in the workflow environment resource right?
we can have multiple sub_environment_configuration
, this will return all of them?
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.
correct. it's an array.
env0/resource_environment.go
Outdated
for i, iSubEnvironment := range iSubEnvironments.([]interface{}) { | ||
subEnviornment := iSubEnvironment.(map[string]interface{}) | ||
|
||
name := d.Get(fmt.Sprintf("sub_environment_configuration.%d.name", i)).(string) |
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.
I may confused you, I updated the #536 issue, every sub_environment_configuration
has a field called alias
, you need to use this field value as the key for the environment.LatestDeploymentLog.WorkflowFile.Environments
and not the name
. alias
is unique in the workflow file as opposed to name
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.
yes... this is a little confusing.
From an API perspective during create there's no "name"/"alias" fields. So I'm unsure what you mean.
We may need to meet to discuss this.
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.
The alias
is not a field, it's actually the keys of the subEnvironment payload we send in the create/deploy request:
{
"first": {
"revision": "feature-branch",
"workspaceName": "env0867fa7",
"configurationChanges": []
},
"third": {
"revision": "main",
"workspaceName": "env0d497f0",
"configurationChanges": []
},
"second": {
"revision": "main",
"workspaceName": "env09b99c4",
"configurationChanges": []
}
}
So basically what you did is good, just change the sub_environment_configuration
field name
to alias
.
have a look at the updated issue desc.
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.
@eladmosh - modified.
@@ -1532,3 +1532,123 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) { | |||
}) | |||
|
|||
} | |||
|
|||
func TestUnitEnvironmentWithoutSubEnvironment(t *testing.T) { |
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.
what do you mean by expanded
?
Solution
Part of the effort to add support for sub environments #536.
In the PR I implemented the create operation.
A unit test was added.