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

TF state correctly detects service owner changes from UI, test updated #499

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Bugfix-20241007-102556.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Bugfix
body: TF state correctly detects service owner changes from UI
time: 2024-10-07T10:25:56.045372-05:00
20 changes: 17 additions & 3 deletions opslevel/resource_opslevel_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,27 @@ func newServiceResourceModel(ctx context.Context, service opslevel.Service, give
Language: OptionalStringValue(service.Language),
LifecycleAlias: OptionalStringValue(service.Lifecycle.Alias),
Name: RequiredStringValue(service.Name),
Note: givenModel.Note,
Owner: OptionalStringValue(givenModel.Owner.ValueString()),
Parent: OptionalStringValue(givenModel.Parent.ValueString()),
Note: OptionalStringValue(service.Note),
Product: OptionalStringValue(service.Product),
TierAlias: OptionalStringValue(service.Tier.Alias),
}

if string(service.Owner.Id) == "" {
serviceResourceModel.Owner = types.StringNull()
} else if string(service.Owner.Id) == givenModel.Owner.ValueString() || service.Owner.Alias == givenModel.Owner.ValueString() {
davidbloss marked this conversation as resolved.
Show resolved Hide resolved
serviceResourceModel.Owner = givenModel.Owner
} else {
serviceResourceModel.Owner = OptionalStringValue(string(service.Owner.Id))
}

if service.Parent == nil {
serviceResourceModel.Parent = types.StringNull()
} else if string(service.Parent.Id) == givenModel.Parent.ValueString() || slices.Contains(service.Parent.Aliases, givenModel.Parent.ValueString()) {
serviceResourceModel.Parent = givenModel.Parent
} else {
serviceResourceModel.Parent = OptionalStringValue(string(service.Parent.Id))
}

if givenModel.Aliases.IsNull() {
serviceResourceModel.Aliases = types.SetNull(types.StringType)
} else {
Expand Down
4 changes: 4 additions & 0 deletions tests/data/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ data "opslevel_domains" "all" {}

data "opslevel_filters" "all" {}

data "opslevel_lifecycles" "all" {}

data "opslevel_repositories" "all" {}

data "opslevel_services" "all" {}
Expand All @@ -10,4 +12,6 @@ data "opslevel_systems" "all" {}

data "opslevel_teams" "all" {}

data "opslevel_tiers" "all" {}

data "opslevel_users" "all" {}
16 changes: 16 additions & 0 deletions tests/data/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ output "all_filters" {
value = data.opslevel_filters.all
}

output "all_lifecycles" {
value = data.opslevel_lifecycles.all
}

output "all_repositories" {
value = data.opslevel_repositories.all
}
Expand All @@ -22,6 +26,10 @@ output "all_teams" {
value = data.opslevel_teams.all
}

output "all_tiers" {
value = data.opslevel_tiers.all
}

output "all_users" {
value = data.opslevel_users.all
}
Expand All @@ -34,6 +42,10 @@ output "first_filter" {
value = data.opslevel_filters.all.filters[0]
}

output "first_lifecycle" {
value = data.opslevel_lifecycles.all.lifecycles[0]
}

output "first_repository" {
value = data.opslevel_repositories.all.repositories[0]
}
Expand All @@ -50,6 +62,10 @@ output "first_team" {
value = data.opslevel_teams.all.teams[0]
}

output "first_tier" {
value = data.opslevel_tiers.all.tiers[0]
}

output "first_user" {
value = data.opslevel_users.all.users[0]
}
Loading
Loading