Skip to content

Commit

Permalink
Fixes needed for Terraform (#513)
Browse files Browse the repository at this point in the history
* Fixes needed for Terraform

* fix tests
  • Loading branch information
rocktavious authored Jan 30, 2025
1 parent c5fbf99 commit 0441fa9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
18 changes: 9 additions & 9 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ type TagAssignInput struct {

// TagCreateInput Specifies the input fields used to create a tag
type TagCreateInput struct {
Alias *Nullable[string] `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The alias of the resource that this tag will be added to (Optional)
Id *Nullable[ID] `json:"id,omitempty" yaml:"id,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the resource that this tag will be added to (Optional)
Alias *string `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The alias of the resource that this tag will be added to (Optional)
Id *ID `json:"id,omitempty" yaml:"id,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the resource that this tag will be added to (Optional)
Key string `json:"key" yaml:"key" example:"example_value"` // The tag's key (Required)
Type *TaggableResource `json:"type,omitempty" yaml:"type,omitempty" example:"Domain"` // The type of resource `alias` refers to, if `alias` is provided (Optional)
Value string `json:"value" yaml:"value" example:"example_value"` // The tag's value (Required)
Expand All @@ -1124,9 +1124,9 @@ type TagRelationshipKeysAssignInput struct {

// TagUpdateInput Specifies the input fields used to update a tag
type TagUpdateInput struct {
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the tag to be updated (Required)
Key *Nullable[string] `json:"key,omitempty" yaml:"key,omitempty" example:"example_value"` // The tag's key (Optional)
Value *Nullable[string] `json:"value,omitempty" yaml:"value,omitempty" example:"example_value"` // The tag's value (Optional)
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the tag to be updated (Required)
Key *string `json:"key,omitempty" yaml:"key,omitempty" example:"example_value"` // The tag's key (Optional)
Value *string `json:"value,omitempty" yaml:"value,omitempty" example:"example_value"` // The tag's value (Optional)
}

// TeamCreateInput Specifies the input fields used to create a team
Expand Down Expand Up @@ -1181,9 +1181,9 @@ type TeamPropertyDefinitionsAssignInput struct {

// TeamUpdateInput Specifies the input fields used to update a team
type TeamUpdateInput struct {
Alias *Nullable[string] `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The alias of the team to be updated (Optional)
Alias *string `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The alias of the team to be updated (Optional)
Group *IdentifierInput `json:"group,omitempty" yaml:"group,omitempty"` // The group this team belongs to (Optional)
Id *Nullable[ID] `json:"id,omitempty" yaml:"id,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team to be updated (Optional)
Id *ID `json:"id,omitempty" yaml:"id,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the team to be updated (Optional)
ManagerEmail *Nullable[string] `json:"managerEmail,omitempty" yaml:"managerEmail,omitempty" example:"example_value"` // The email of the user who manages the team (Optional)
Members *[]TeamMembershipUserInput `json:"members,omitempty" yaml:"members,omitempty" example:"[]"` // A set of emails that identify users in OpsLevel (Optional)
Name *Nullable[string] `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The team's display name (Optional)
Expand All @@ -1196,8 +1196,8 @@ type ToolCreateInput struct {
Category ToolCategory `json:"category" yaml:"category" example:"admin"` // The category that the tool belongs to (Required)
DisplayName string `json:"displayName" yaml:"displayName" example:"example_value"` // The display name of the tool (Required)
Environment *Nullable[string] `json:"environment,omitempty" yaml:"environment,omitempty" example:"example_value"` // The environment that the tool belongs to (Optional)
ServiceAlias *Nullable[string] `json:"serviceAlias,omitempty" yaml:"serviceAlias,omitempty" example:"example_value"` // The alias of the service the tool will be assigned to (Optional)
ServiceId *Nullable[ID] `json:"serviceId,omitempty" yaml:"serviceId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the service the tool will be assigned to (Optional)
ServiceAlias *string `json:"serviceAlias,omitempty" yaml:"serviceAlias,omitempty" example:"example_value"` // The alias of the service the tool will be assigned to (Optional)
ServiceId *ID `json:"serviceId,omitempty" yaml:"serviceId,omitempty" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the service the tool will be assigned to (Optional)
Url string `json:"url" yaml:"url" example:"example_value"` // The URL of the tool (Required)
}

Expand Down
13 changes: 8 additions & 5 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func (client *Client) CreateTags(identifier string, tags map[string]string) ([]T
Value: value,
}
if IsID(identifier) {
input.Id = RefOf(ID(identifier))
input.Id = NewID(identifier)
} else {
input.Alias = RefOf(identifier)
input.Alias = &identifier
}
newTag, err := client.CreateTag(input)
if err != nil {
Expand Down Expand Up @@ -166,8 +166,10 @@ func (client *Client) UpdateTag(input TagUpdateInput) (*Tag, error) {
var m struct {
Payload TagUpdatePayload `graphql:"tagUpdate(input: $input)"`
}
if err := ValidateTagKey(input.Key.Value); err != nil {
return nil, err
if input.Key != nil {
if err := ValidateTagKey(*input.Key); err != nil {
return nil, err
}
}
v := PayloadVariables{
"input": input,
Expand Down Expand Up @@ -199,8 +201,9 @@ func (client *Client) ReconcileTags(resourceType TaggableResourceInterface, tags
toCreate, toDelete := reconcileTags(tagConnection.Nodes, tagsDesired)
for _, tag := range toCreate {
taggableResourceType := resourceType.ResourceType()
taggableResourceID := resourceType.ResourceId()
_, err := client.CreateTag(TagCreateInput{
Id: RefOf(resourceType.ResourceId()),
Id: &taggableResourceID,
Type: &taggableResourceType,
Key: tag.Key,
Value: tag.Value,
Expand Down
6 changes: 4 additions & 2 deletions tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ func TestUpdateTag(t *testing.T) {
)

client := BestTestClient(t, "tagUpdate", testRequest)
hello := "hello"
world := "world!"
// Act
result, err := client.UpdateTag(ol.TagUpdateInput{
Id: id1,
Key: ol.RefOf("hello"),
Value: ol.RefOf("world!"),
Key: &hello,
Value: &world,
})
// Assert
autopilot.Ok(t, err)
Expand Down
2 changes: 1 addition & 1 deletion team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func TestUpdateTeam(t *testing.T) {
// Arrange
input := autopilot.Register[ol.TeamUpdateInput]("team_update_input",
ol.TeamUpdateInput{
Id: ol.RefOf(id1),
Id: &id1,
Responsibilities: ol.RefOf("Foo & bar"),
ParentTeam: ol.NewIdentifier("parent_team"),
},
Expand Down

0 comments on commit 0441fa9

Please sign in to comment.