-
Notifications
You must be signed in to change notification settings - Fork 3
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
Export Teams and team memberships to Terraform #206
Changes from 6 commits
f4cdf15
e3b14af
fc47d58
c242a9d
197a64e
86a9fe4
4cefc30
edebe3c
0e02e33
93831d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kind: Bugfix | ||
body: Fix exporting Teams in Terraform to have up to have a schema compatible with | ||
v0.8.13 | ||
time: 2023-11-27T17:18:54.983105-05:00 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: Feature | ||
body: Support for exporting Team Memberships in Terraform | ||
time: 2023-11-27T17:19:23.084993-05:00 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,30 +310,49 @@ func exportServices(c *opslevel.Client, shell *os.File, directory string) { | |
func exportTeams(c *opslevel.Client, config *os.File, shell *os.File) { | ||
shell.WriteString("# Teams\n") | ||
|
||
teamConfig := `resource "opslevel_team" "%s" { | ||
name = "%s" | ||
manager_email = "%s" | ||
parent = "%s" | ||
%s | ||
%s | ||
teamConfig := `resource "opslevel_team" "%s" {%s | ||
} | ||
|
||
` | ||
resp, err := c.ListTeams(nil) | ||
teams := resp.Nodes | ||
cobra.CheckErr(err) | ||
for _, team := range teams { | ||
teamBody := "" | ||
|
||
aliases := flattenAliases(team.Aliases) | ||
if len(aliases) > 0 { | ||
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. As of 12 days ago team |
||
aliases = fmt.Sprintf("aliases = [\"%s\"]", aliases) | ||
teamBody += fmt.Sprintf("\n aliases = [\"%s\"]", aliases) | ||
} | ||
teamBody += fmt.Sprintf("\n name = \"%s\"", team.Name) | ||
|
||
if len(team.Group.Alias) > 0 { | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
teamBody += fmt.Sprintf("\n group = \"%s\"", team.Group.Alias) | ||
} | ||
membersOutput := "" | ||
for _, member := range team.Memberships.Nodes { | ||
memberConfig := ` | ||
member { | ||
email = "%s" | ||
role = "%s" | ||
}` | ||
membersOutput += fmt.Sprintf(memberConfig, member.User.Email, member.Role) | ||
} | ||
if len(membersOutput) > 0 { | ||
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. This 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. Actually where 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. Implemented these suggestions |
||
teamBody += membersOutput | ||
} | ||
if len(team.ParentTeam.Alias) > 0 { | ||
teamBody += fmt.Sprintf("\n parent = [\"%s\"]", team.ParentTeam.Alias) | ||
} | ||
if len(team.Responsibilities) > 0 { | ||
responsibilities := buildMultilineStringArg("responsibilities", team.Responsibilities) | ||
teamBody += fmt.Sprintf("\n %s", responsibilities) | ||
} | ||
|
||
config.WriteString(templateConfig( | ||
teamConfig, | ||
team.Alias, | ||
team.Name, | ||
team.Manager.Email, | ||
team.ParentTeam.Alias, | ||
aliases, | ||
buildMultilineStringArg("responsibilities", team.Responsibilities), | ||
teamBody, | ||
)) | ||
shell.WriteString(fmt.Sprintf("terraform import opslevel_team.%s %s\n", team.Alias, team.Id)) | ||
} | ||
|
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.
Can we please introduce
strings.Builder
here?We can set
teamBody := strings.Builder{}
just above this for loop then:config.WriteString(templateConfig()
belowRunning this command is surprisingly slow and this would be a small step in a more optimized direction IMO
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.
Added!