Skip to content

Commit bda9225

Browse files
committed
create module
1 parent dd21010 commit bda9225

File tree

9 files changed

+473
-0
lines changed

9 files changed

+473
-0
lines changed

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Variable files
2+
terraform.tfvars
3+
4+
### https://raw.github.com/github/gitignore/abad92dac5a4306f72242dae3bca6e277bce3615/Terraform.gitignore
5+
6+
# Compiled files
7+
*.tfstate
8+
*.tfstate.backup
9+
*.tfvars
10+
11+
**/.terraform.lock.hcl
12+
13+
# Go vendor directory
14+
vendor/
15+
16+
# Terraform directory
17+
.terraform/
18+
terraform.tfstate.d/
19+
logs/
20+
21+
# Files generated by terratest
22+
.test-data/
23+
24+
# Terraform log file
25+
terraform.log
26+
27+
### https://raw.github.com/github/gitignore/abad92dac5a4306f72242dae3bca6e277bce3615/Global/Vim.gitignore
28+
29+
# swap
30+
[._]*.s[a-w][a-z]
31+
[._]s[a-w][a-z]
32+
# session
33+
Session.vim
34+
# temporary
35+
.netrwhist
36+
*~
37+
# auto-generated tag files
38+
tags
39+
40+
# IDE configs
41+
.idea
42+
43+
# Ruby download package lock file.
44+
Gemfile.lock
45+
46+
# mac folder attribute file
47+
.DS_Store
48+
.terraform.tfstate.lock.info
49+
50+
# SSH Key
51+
private_ssh_key
52+
53+
# generated readme by the pr-check job
54+
55+
README-generated.md
56+
57+
**/override.tf
58+
59+
.tflint.hcl
60+
.tflint_example.hcl
61+
.tflint.merged.hcl
62+
.tflint_example.merged.hcl
63+
64+
tfmod-scaffold/
65+
scripts
66+
test/go.sum
67+
68+
/TestRecord
69+
**/TestRecord.md.tmp
70+
71+
tfvmmakefile

examples/default/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
resource "random_password" "password" {
6+
length = 20
7+
min_lower = 1
8+
min_numeric = 1
9+
min_special = 1
10+
min_upper = 1
11+
}
12+
13+
module "postgresql" {
14+
source = "../../"
15+
16+
resource_group_name = ""
17+
location = ""
18+
19+
server_name = "test-server-postgresql"
20+
administrator_login = "psql"
21+
administrator_password = random_password.password.result
22+
}

examples/default/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output "test_postgresql_server_id" {
2+
value = module.postgresql.server_id
3+
}
4+
5+
output "test_random_password" {
6+
sensitive = true
7+
value = random_password.password.result
8+
}

examples/replica/main.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
resource "random_password" "password" {
6+
length = 20
7+
min_lower = 1
8+
min_numeric = 1
9+
min_special = 1
10+
min_upper = 1
11+
}
12+
13+
module "postgresql" {
14+
source = "../../"
15+
16+
resource_group_name = ""
17+
location = ""
18+
19+
server_name = "test-pg-primary"
20+
administrator_login = "psql"
21+
administrator_password = random_password.password.result
22+
}
23+
24+
resource "time_sleep" "sleep" {
25+
create_duration = "1m"
26+
27+
depends_on = [module.postgresql]
28+
}
29+
30+
module "postgresql_replica" {
31+
source = "../../"
32+
33+
resource_group_name = ""
34+
location = ""
35+
36+
server_name = "test-pg-replica"
37+
administrator_login = "psql"
38+
administrator_password = random_password.password.result
39+
40+
create_mode = "Replica"
41+
creation_source_server_id = module.postgresql.server_id
42+
43+
depends_on = [time_sleep.sleep]
44+
}

examples/replica/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
output "test_postgresql_replica_server_id" {
2+
value = module.postgresql_replica.server_id
3+
}
4+
5+
output "test_postgresql_server_id" {
6+
value = module.postgresql.server_id
7+
}
8+
9+
output "test_random_password" {
10+
sensitive = true
11+
value = random_password.password.result
12+
}

main.tf

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
resource "azurerm_postgresql_server" "server" {
2+
location = var.location
3+
name = var.server_name
4+
resource_group_name = var.resource_group_name
5+
sku_name = var.sku_name
6+
ssl_enforcement_enabled = var.ssl_enforcement_enabled
7+
version = var.server_version
8+
administrator_login = var.administrator_login
9+
administrator_login_password = var.administrator_password
10+
auto_grow_enabled = var.auto_grow_enabled
11+
backup_retention_days = var.backup_retention_days
12+
create_mode = var.create_mode
13+
creation_source_server_id = var.creation_source_server_id
14+
geo_redundant_backup_enabled = var.geo_redundant_backup_enabled
15+
infrastructure_encryption_enabled = var.infrastructure_encryption_enabled
16+
public_network_access_enabled = var.public_network_access_enabled
17+
ssl_minimal_tls_version_enforced = var.ssl_minimal_tls_version_enforced
18+
storage_mb = var.storage_mb
19+
tags = var.tags
20+
21+
dynamic "threat_detection_policy" {
22+
for_each = nonsensitive(var.threat_detection_policy) != null ? ["threat_detection_policy"] : []
23+
24+
content {
25+
disabled_alerts = var.threat_detection_policy.disabled_alerts
26+
email_account_admins = var.threat_detection_policy.email_account_admins
27+
email_addresses = var.threat_detection_policy.email_addresses
28+
enabled = var.threat_detection_policy.enabled
29+
retention_days = var.threat_detection_policy.retention_days
30+
storage_account_access_key = var.threat_detection_policy.storage_account_access_key
31+
storage_endpoint = var.threat_detection_policy.storage_endpoint
32+
}
33+
}
34+
}
35+
36+
resource "azurerm_postgresql_database" "dbs" {
37+
count = length(var.db_names)
38+
39+
charset = var.db_charset
40+
collation = var.db_collation
41+
name = var.db_names[count.index]
42+
resource_group_name = var.resource_group_name
43+
server_name = azurerm_postgresql_server.server.name
44+
}
45+
46+
resource "azurerm_postgresql_firewall_rule" "firewall_rules" {
47+
count = length(var.firewall_rules)
48+
49+
end_ip_address = var.firewall_rules[count.index]["end_ip"]
50+
name = format("%s%s", var.firewall_rule_prefix, lookup(var.firewall_rules[count.index], "name", count.index))
51+
resource_group_name = var.resource_group_name
52+
server_name = azurerm_postgresql_server.server.name
53+
start_ip_address = var.firewall_rules[count.index]["start_ip"]
54+
}
55+
56+
resource "azurerm_postgresql_virtual_network_rule" "vnet_rules" {
57+
count = length(var.vnet_rules)
58+
59+
name = format("%s%s", var.vnet_rule_name_prefix, lookup(var.vnet_rules[count.index], "name", count.index))
60+
resource_group_name = var.resource_group_name
61+
server_name = azurerm_postgresql_server.server.name
62+
subnet_id = var.vnet_rules[count.index]["subnet_id"]
63+
}
64+
65+
resource "azurerm_postgresql_configuration" "db_configs" {
66+
count = length(keys(var.postgresql_configurations))
67+
68+
name = element(keys(var.postgresql_configurations), count.index)
69+
resource_group_name = var.resource_group_name
70+
server_name = azurerm_postgresql_server.server.name
71+
value = element(values(var.postgresql_configurations), count.index)
72+
}
73+

outputs.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
output "administrator_login" {
2+
description = "The Administrator login for the PostgreSQL Server"
3+
value = var.administrator_login
4+
}
5+
6+
output "administrator_password" {
7+
description = "The Password associated with the `administrator_login` for the PostgreSQL Server"
8+
sensitive = true
9+
value = var.administrator_password
10+
}
11+
12+
output "database_ids" {
13+
description = "The list of all database resource ids"
14+
value = [azurerm_postgresql_database.dbs[*].id]
15+
}
16+
17+
output "firewall_rule_ids" {
18+
description = "The list of all firewall rule resource ids"
19+
value = [azurerm_postgresql_firewall_rule.firewall_rules[*].id]
20+
}
21+
22+
output "server_fqdn" {
23+
description = "The fully qualified domain name (FQDN) of the PostgreSQL server"
24+
value = azurerm_postgresql_server.server.fqdn
25+
}
26+
27+
output "server_id" {
28+
description = "The resource id of the PostgreSQL server"
29+
value = azurerm_postgresql_server.server.id
30+
}
31+
32+
output "server_name" {
33+
description = "The name of the PostgreSQL server"
34+
value = azurerm_postgresql_server.server.name
35+
}
36+
37+
output "vnet_rule_ids" {
38+
description = "The list of all vnet rule resource ids"
39+
value = [azurerm_postgresql_virtual_network_rule.vnet_rules[*].id]
40+
}

0 commit comments

Comments
 (0)