Skip to content

Commit

Permalink
better team export
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Nov 27, 2023
1 parent ad801cd commit 53b673c
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/cmd/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ func exportTeams(c *opslevel.Client, config *os.File, shell *os.File) {
shell.WriteString("# Teams\n")

teamConfig := `resource "opslevel_team" "%s" {
%s
name = "%s"
manager_email = "%s"
parent = "%s"
%s
%s
%s
%s
}
Expand All @@ -326,13 +327,45 @@ func exportTeams(c *opslevel.Client, config *os.File, shell *os.File) {
if len(aliases) > 0 {
aliases = fmt.Sprintf("aliases = [\"%s\"]", aliases)
}

group := ""
if team.Group.Alias != "" {
group = fmt.Sprintf("group = [\"%s\"]", team.Group.Alias)
}

membersOutput := ""
for _, member := range team.Memberships.Nodes {
memberConfig := `member {
email = "%s"
role = "%s"
}
`

config.WriteString(templateConfig(
memberConfig,
member.User.Email,
member.Role,
))
membersOutput += memberConfig
}

parent := ""
if team.ParentTeam.Alias != "" {
parent = fmt.Sprintf("parent = [\"%s\"]", team.ParentTeam.Alias)
}

config.WriteString(templateConfig(
teamConfig,
team.Alias,
team.Name,
team.Manager.Email,
team.ParentTeam.Alias,

// Required
aliases,
team.Name,

// Optional
group,
membersOutput,
parent,
buildMultilineStringArg("responsibilities", team.Responsibilities),
))
shell.WriteString(fmt.Sprintf("terraform import opslevel_team.%s %s\n", team.Alias, team.Id))
Expand Down

0 comments on commit 53b673c

Please sign in to comment.