OpsLevel / terraform-provider-opslevel

Terraform provider for OpsLevel.com
https://registry.terraform.io/providers/OpsLevel/opslevel/latest/docs
MIT License
8 stars 5 forks source link

convert aliases attribute from list to set #354

Closed davidbloss closed 2 months ago

davidbloss commented 2 months ago

Issues

aliases field has issues

Changelog

Convert aliases field in opslevel_infrastructure, opslevel_service, and opslevel_team from list type to set. This is a sensible solution to the unordered nature of aliases on return.

Tophatting

With this config

# main.tf
resource "opslevel_infrastructure" "example" {
  aliases = []
  owner   = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzMg"
  schema  = "Database"
  data = jsonencode({
    name = "my-database"
  })
}

resource "opslevel_service" "example" {
  name    = "frosting-patrol1"
  aliases = []
}

resource "opslevel_team" "example" {
  name             = "bake-off2"
  responsibilities = "Baking cakes"
  aliases          = []
}

Create resources with empty (non-null) aliases, terraform apply

opslevel_team.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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.example will be updated in-place
  ~ resource "opslevel_infrastructure" "example" {
      + aliases = []
        id      = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk"
        # (3 unchanged attributes hidden)
    }

  # opslevel_service.example will be updated in-place
  ~ resource "opslevel_service" "example" {
      + aliases = []
        id      = "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ"
        name    = "frosting-patrol1"
    }

  # opslevel_team.example will be updated in-place
  ~ resource "opslevel_team" "example" {
      + aliases          = []
        id               = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg"
        name             = "bake-off2"
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 3 to change, 0 to destroy.
opslevel_team.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]
opslevel_team.example: Modifications complete after 0s [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Modifications complete after 0s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifications complete after 1s [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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

Update config, populate aliases

resource "opslevel_infrastructure" "example" {
  aliases = ["lkasjd121fkj12", "b342ufyoiayw12"]
  owner   = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzMg"
  schema  = "Database"
  data = jsonencode({
    name = "my-database"
  })
}

resource "opslevel_service" "example" {
  name    = "frosting-patrol1"
  aliases = ["lkasjdfkj12", "bufyoiayw12"]
}

resource "opslevel_team" "example" {
  name             = "bake-off2"
  responsibilities = "Baking cakes"
  aliases          = ["lkasjdfkj", "bufyoiayw"]
}

Update resources to add aliases, terraform apply

opslevel_team.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_service.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]
opslevel_infrastructure.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]

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.example will be updated in-place
  ~ resource "opslevel_infrastructure" "example" {
      ~ aliases = [
          + "b342ufyoiayw12",
          + "lkasjd121fkj12",
        ]
        id      = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk"
        # (3 unchanged attributes hidden)
    }

  # opslevel_service.example will be updated in-place
  ~ resource "opslevel_service" "example" {
      ~ aliases = [
          + "bufyoiayw12",
          + "lkasjdfkj12",
        ]
        id      = "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ"
        name    = "frosting-patrol1"
    }

  # opslevel_team.example will be updated in-place
  ~ resource "opslevel_team" "example" {
      ~ aliases          = [
          + "bufyoiayw",
          + "lkasjdfkj",
        ]
        id               = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg"
        name             = "bake-off2"
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 3 to change, 0 to destroy.
opslevel_infrastructure.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]
opslevel_team.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_team.example: Modifications complete after 1s [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Modifications complete after 1s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifications complete after 2s [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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

Update config, remove aliases

resource "opslevel_infrastructure" "example" {
  # aliases = ["lkasjd121fkj12", "b342ufyoiayw12"]
  owner   = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzMg"
  schema  = "Database"
  data = jsonencode({
    name = "my-database"
  })
}

resource "opslevel_service" "example" {
  name    = "frosting-patrol1"
  # aliases = ["lkasjdfkj12", "bufyoiayw12"]
}

resource "opslevel_team" "example" {
  name             = "bake-off2"
  responsibilities = "Baking cakes"
  # aliases          = ["lkasjdfkj", "bufyoiayw"]
}

Update resources to remove aliases (null - not empty), terraform apply

opslevel_team.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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.example will be updated in-place
  ~ resource "opslevel_infrastructure" "example" {
      - aliases = [] -> null
        id      = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk"
        # (3 unchanged attributes hidden)
    }

  # opslevel_service.example will be updated in-place
  ~ resource "opslevel_service" "example" {
      - aliases = [] -> null
        id      = "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ"
        name    = "frosting-patrol1"
    }

  # opslevel_team.example will be updated in-place
  ~ resource "opslevel_team" "example" {
      - aliases          = [] -> null
        id               = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg"
        name             = "bake-off2"
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 3 to change, 0 to destroy.
opslevel_infrastructure.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]
opslevel_team.example: Modifying... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_team.example: Modifications complete after 0s [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Modifications complete after 0s [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Modifications complete after 1s [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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

Destroy test resources, terraform destroy

opslevel_team.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_infrastructure.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_service.example: Refreshing state... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]

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

Terraform will perform the following actions:

  # opslevel_infrastructure.example will be destroyed
  - resource "opslevel_infrastructure" "example" {
      - data   = jsonencode(
            {
              - name = "my-database"
            }
        ) -> null
      - id     = "Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk" -> null
      - owner  = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xNzQzMg" -> null
      - schema = "Database" -> null
    }

  # opslevel_service.example will be destroyed
  - resource "opslevel_service" "example" {
      - id   = "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ" -> null
      - name = "frosting-patrol1" -> null
    }

  # opslevel_team.example will be destroyed
  - resource "opslevel_team" "example" {
      - id               = "Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg" -> null
      - name             = "bake-off2" -> null
      - responsibilities = "Baking cakes" -> null
    }

Plan: 0 to add, 0 to change, 3 to destroy.
opslevel_team.example: Destroying... [id=Z2lkOi8vb3BzbGV2ZWwvVGVhbS8xOTE2Mg]
opslevel_service.example: Destroying... [id=Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS8xMjQwMDQ]
opslevel_infrastructure.example: Destroying... [id=Z2lkOi8vb3BzbGV2ZWwvRW50aXR5T2JqZWN0LzI0OTgyMTk]
opslevel_infrastructure.example: Destruction complete after 0s
opslevel_team.example: Destruction complete after 0s
opslevel_service.example: Destruction complete after 2s

Destroy complete! Resources: 3 destroyed.