尝试使用https://registry.terraform.io/modules/Azure/database/azurerm/1.0.1
中的数据库模块我已经从我的工作站在Azure中创建了对象,因此所有基础知识都就位了。
我将main / variables / outputs文件复制到一个文件夹(sql),然后使用下面的示例进行调用。
# Configure the Azure Provider
provider "azurerm" {}
module "sql-database" {
source = "./sql"
resource_group_name = "myapp"
location = "westus"
db_name = "mydatabase"
sql_admin_username = "mradministrator"
sql_password = "P@ssw0rd12345!"
tags = {
environment = "dev"
costcenter = "it"
}
}
当我运行terraform init时,出现以下错误,知道我在做什么错吗?
PS C:\GITHUB\terraform_azure\app> terraform init
Initializing modules...
- module.sql-database
Error getting plugins: 9 problems:
- output 'sql_server_name': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.name
- output 'sql_server_location': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.location
- output 'sql_server_version': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.version
- output 'sql_server_fqdn': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.fully_qualified_domain_name
- output 'connection_string': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.administrator_login_password
- output 'connection_string': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.fully_qualified_domain_name
- output 'connection_string': unknown resource 'azurerm_sql_database.db'
referenced in variable azurerm_sql_database.db.name
- output 'connection_string': unknown resource 'azurerm_sql_server.server'
referenced in variable azurerm_sql_server.server.administrator_login
- output 'database_name': unknown resource 'azurerm_sql_database.db'
referenced in variable azurerm_sql_database.db.name
答案 0 :(得分:0)
# Configure the Azure Provider
provider "azurerm" {}
module "sql-database" {
version = "1.0.1"
source = "./sql"
resource_group_name = "myapp"
location = "westus"
db_name = "mydatabase"
sql_admin_username = "mradministrator"
sql_password = "P@ssw0rd12345!"
tags = {
environment = "dev"
costcenter = "it"
}
}
将主文件更新到上面,并且可以工作(再次,我添加了版本号。。不确定为什么使它工作!我没有在数据库中看到任何内容,主文件中没有任何有关版本的信息。完成!