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

Support for aliases on Infrastructure Resources #150

Merged
6 commits merged into from
Nov 8, 2023
Merged

Support for aliases on Infrastructure Resources #150

6 commits merged into from
Nov 8, 2023

Conversation

ghost
Copy link

@ghost ghost commented Nov 7, 2023

Issues

https://github.com/OpsLevel/team-platform/issues/112

Allow aliases to be managed on infra resources just like they are managed on services.

NOTE that unlike services, infra resources don't have a slug/friendly_id that is placed inside the aliases array. So using ManagedAliases is not necessary!

Changelog

  • Add support for alias management on infra resources
  • Fix minor bugs in Service
  • Make a changie entry

Tophatting

Create infra resource with no aliases:

~/repos/terraform-provider-opslevel/workspace infraresaliases !2 ❯ cat main.tf && task apply                                                                                                                                                                        5s Ruby 3.0.0 04:55:10 pm
resource "opslevel_infrastructure" "new_tf_infra" {
    schema = "Database"
    data = jsonencode({
        name = "a new infra res made in tf"
    })
    provider_data {
        account = "dev"
    }
}
task: [terraform-command] terraform -chdir=/Users/taimoorahmad/repos/terraform-provider-opslevel/workspace apply 

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # opslevel_infrastructure.new_tf_infra will be created
  + resource "opslevel_infrastructure" "new_tf_infra" {
      + data         = jsonencode(
            {
              + name = "a new infra res made in tf"
            }
        )
      + id           = (known after apply)
      + last_updated = (known after apply)
      + schema       = "Database"

      + provider_data {
          + account = "dev"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

opslevel_infrastructure.new_tf_infra: Creating...
opslevel_infrastructure.new_tf_infra: Creation complete after 1s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Add aliases:

~/repos/terraform-provider-opslevel/workspace infraresaliases !2 ❯ cat main.tf && task apply                                                                                                                                                                        4s Ruby 3.0.0 04:55:20 pm
resource "opslevel_infrastructure" "new_tf_infra" {
    schema = "Database"
    data = jsonencode({
        name = "a new infra res made in tf"
    })
    provider_data {
        account = "dev"
    }
    aliases = ["alias1", "alias2"]
}
task: [terraform-command] terraform -chdir=/Users/taimoorahmad/repos/terraform-provider-opslevel/workspace apply 
opslevel_infrastructure.new_tf_infra: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # opslevel_infrastructure.new_tf_infra will be updated in-place
  ~ resource "opslevel_infrastructure" "new_tf_infra" {
      ~ aliases = [
          + "alias1",
          + "alias2",
        ]
        id      = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

opslevel_infrastructure.new_tf_infra: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]
opslevel_infrastructure.new_tf_infra: Modifications complete after 2s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Remove the aliases:

~/repos/terraform-provider-opslevel/workspace infraresaliases !2 ❯ cat main.tf && task apply                                                                                                                                                                        5s Ruby 3.0.0 04:55:38 pm
resource "opslevel_infrastructure" "new_tf_infra" {
    schema = "Database"
    data = jsonencode({
        name = "a new infra res made in tf"
    })
    provider_data {
        account = "dev"
    }
    aliases = []
}
task: [terraform-command] terraform -chdir=/Users/taimoorahmad/repos/terraform-provider-opslevel/workspace apply 
opslevel_infrastructure.new_tf_infra: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # opslevel_infrastructure.new_tf_infra will be updated in-place
  ~ resource "opslevel_infrastructure" "new_tf_infra" {
      ~ aliases      = [
          - "alias1",
          - "alias2",
        ]
        id           = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng"
        # (3 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

opslevel_infrastructure.new_tf_infra: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]
opslevel_infrastructure.new_tf_infra: Modifications complete after 3s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

@ghost ghost self-assigned this Nov 7, 2023
Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #150 (078489e) into main (d5d8301) will decrease coverage by 0.16%.
Report is 4 commits behind head on main.
The diff coverage is 6.25%.

@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
- Coverage   44.89%   44.73%   -0.16%     
==========================================
  Files          70       70              
  Lines        5649     5671      +22     
==========================================
+ Hits         2536     2537       +1     
- Misses       3111     3132      +21     
  Partials        2        2              
Files Coverage Δ
opslevel/resource_opslevel_service.go 35.48% <0.00%> (ø)
opslevel/resource_opslevel_infra.go 45.62% <7.40%> (-7.71%) ⬇️

... and 1 file with indirect coverage changes

@@ -234,7 +234,7 @@ func resourceServiceCreate(d *schema.ResourceData, client *opslevel.Client) erro
}
_, err := client.ServiceApiDocSettingsUpdate(string(resource.Id), docPath.(string), source)
if err != nil {
log.Error().Err(err).Msgf("failed to update service '%s' api doc settings", resource.ManagedAliases[0])
log.Error().Err(err).Msgf("failed to update service '%s' api doc settings", resource.Aliases[0])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that this is a bug that was introduced in services. If the user has no set aliases, this line will crash instead of erroring. Aliases[0] is being used because it's guaranteed that the slug/friendly_id will be present there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@ghost
Copy link
Author

ghost commented Nov 7, 2023

query {
  account {
    infrastructureResources {
      nodes {
        id
        name
        aliases
      }
    }
  }
}
{
  "data": {
    "account": {
      "infrastructureResources": {
        "nodes": [
          {
            "id": "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzU1OTczOA",
            "name": "my-big-query",
            "aliases": []
          },
          {
            "id": "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0Lzc3ODI5Ng",
            "name": "a new infra res made in tf",
            "aliases": [
              "alias3" // added this in tf :) 
            ]
          }
        ]
      }
    }
  }
}

@ghost ghost changed the title Support for aliases in Infrastructure Resources Support for aliases on Infrastructure Resources Nov 7, 2023
@ghost ghost merged commit 1d3b343 into main Nov 8, 2023
4 of 5 checks passed
@ghost ghost deleted the infraresaliases branch November 8, 2023 15:22
@taimoorgit taimoorgit self-assigned this Mar 25, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants