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

Feat: add support for subenvironments #571

Merged
merged 2 commits into from
Jan 19, 2023

Conversation

TomerHeber
Copy link
Collaborator

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.

@@ -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 {
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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")
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

for i, iSubEnvironment := range iSubEnvironments.([]interface{}) {
subEnviornment := iSubEnvironment.(map[string]interface{})

name := d.Get(fmt.Sprintf("sub_environment_configuration.%d.name", i)).(string)
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

@eladmosh eladmosh Jan 18, 2023

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.

Copy link
Collaborator Author

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) {
Copy link
Contributor

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?

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Jan 19, 2023
@TomerHeber TomerHeber merged commit 656467f into main Jan 19, 2023
@TomerHeber TomerHeber deleted the feat-subenvironment-support-#536_4 branch January 19, 2023 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature provider ready to merge PR approved - can be merged once the PR owner is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants