generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
835 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
page_title: "sql_migrate Resource - terraform-provider-sql" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# Resource `sql_migrate` | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "sql_migrate" "users" { | ||
migration { | ||
up = <<SQL | ||
CREATE TABLE users ( | ||
user_id integer unique, | ||
name varchar(40), | ||
email varchar(40) | ||
); | ||
SQL | ||
down = "DROP TABLE IF EXISTS users;" | ||
} | ||
migration { | ||
up = "INSERT INTO users VALUES (1, 'Paul Tyng', '[email protected]');" | ||
down = "DELETE FROM users WHERE user_id = 1;" | ||
} | ||
} | ||
data "sql_query" "users" { | ||
# run this query after the migration | ||
depends_on = [sql_migrate.users] | ||
query = "select * from users" | ||
} | ||
output "rowcount" { | ||
value = length(data.sql_query.users.result) | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
### Optional | ||
|
||
- **migration** (Block List) (see [below for nested schema](#nestedblock--migration)) | ||
|
||
### Read-only | ||
|
||
- **id** (String, Read-only, Deprecated) The ID of this resource. | ||
|
||
<a id="nestedblock--migration"></a> | ||
### Nested Schema for `migration` | ||
|
||
Required: | ||
|
||
- **down** (String, Required) | ||
- **up** (String, Required) | ||
|
||
Optional: | ||
|
||
- **id** (String, Optional) Identifier can be any string to help identifying the migration in the source. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_providers { | ||
sql = { | ||
source = "paultyng/sql" | ||
} | ||
} | ||
} | ||
|
||
provider "sql" { | ||
url = "postgres://postgres:tf@localhost:5432/tftest?sslmode=disable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resource "sql_migrate" "users" { | ||
migration { | ||
up = <<SQL | ||
CREATE TABLE users ( | ||
user_id integer unique, | ||
name varchar(40), | ||
email varchar(40) | ||
); | ||
SQL | ||
|
||
down = "DROP TABLE IF EXISTS users;" | ||
} | ||
|
||
migration { | ||
up = "INSERT INTO users VALUES (1, 'Paul Tyng', '[email protected]');" | ||
down = "DELETE FROM users WHERE user_id = 1;" | ||
} | ||
} | ||
|
||
data "sql_query" "users" { | ||
# run this query after the migration | ||
depends_on = [sql_migrate.users] | ||
|
||
query = "select * from users" | ||
} | ||
|
||
output "rowcount" { | ||
value = length(data.sql_query.users.result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.