aidanmelen / terraform-provider-snowsql

Terraform SnowSQL provider
https://registry.terraform.io/providers/aidanmelen/snowsql/latest
Other
22 stars 10 forks source link

feat(81): make name optional and default to random id when not set. #84

Closed aidanmelen closed 1 year ago

aidanmelen commented 1 year ago

Feats

Example 1

Removing name after specified during resource creation:

  1. Create resource with name:
resource "snowsql_exec" "role" {
  name = "my_role"

  create {
    statements = "CREATE ROLE IF NOT EXISTS my_role"
  }

  delete {
    statements = "DROP ROLE IF EXISTS my_role"
  }
}

output:

  # snowsql_exec.role will be created
  + resource "snowsql_exec" "role" {
      + id           = (known after apply)
      + name         = "my_role"
      + read_results = (sensitive value)

      + create {
          + number_of_statements = (known after apply)
          + statements           = "CREATE ROLE IF NOT EXISTS my_role"
        }

      + delete {
          + number_of_statements = (known after apply)
          + statements           = "DROP ROLE IF EXISTS my_role"
        }
    }
  1. and remove the name argument:

    resource "snowsql_exec" "role" {
    # name = "my_role"
    
    create {
    statements = "CREATE ROLE IF NOT EXISTS my_role"
    }
    
    delete {
    statements = "DROP ROLE IF EXISTS my_role"
    }
    }

output:

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:

  # snowsql_exec.role will be updated in-place
  ~ resource "snowsql_exec" "role" {
        id   = "my_role"
      - name = "my_role" -> null

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
snowsql_exec.role: Modifying... [id=my_role]
snowsql_exec.role: Modifications complete after 0s [id=my_role]

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

The original id should persist.

Example 2

create new resource without specifying the name argument:

  1. Create resource with name:
resource "snowsql_exec" "role" {
  create {
    statements = "CREATE ROLE IF NOT EXISTS my_role"
  }

  delete {
    statements = "DROP ROLE IF EXISTS my_role"
  }
}

output:

   # snowsql_exec.role will be created
  + resource "snowsql_exec" "role" {
      + id           = (known after apply)
      + read_results = (sensitive value)

      + create {
          + number_of_statements = (known after apply)
          + statements           = "CREATE ROLE IF NOT EXISTS my_role"
        }

      + delete {
          + number_of_statements = (known after apply)
          + statements           = "DROP ROLE IF EXISTS my_role"
        }
    }
  1. and add the name argument.

    resource "snowsql_exec" "role" {
    name = "my_role"
    
    create {
    statements = "CREATE ROLE IF NOT EXISTS my_role"
    }
    
    delete {
    statements = "DROP ROLE IF EXISTS my_role"
    }
    }

output:

snowsql_exec.role: Refreshing state... [id=cfs3dsqnv5cr4jj9bql0]

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:

  # snowsql_exec.role will be updated in-place
  ~ resource "snowsql_exec" "role" {
        id   = "cfs3dsqnv5cr4jj9bql0"
      + name = "my_role"

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
snowsql_exec.role: Modifying... [id=cfs3dsqnv5cr4jj9bql0]
snowsql_exec.role: Modifications complete after 0s [id=cfs3dsqnv5cr4jj9bql0]

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

The original id should persist.