From ba0aa4dd444aa7198c7f835412fd2ff25992c9ad Mon Sep 17 00:00:00 2001 From: Thomas Meckel Date: Tue, 13 Jun 2023 18:37:01 +0000 Subject: [PATCH 1/4] fix: corrected exclude **/schema.go in .gitignore --- .gitignore | 2 +- go.work.sum | 5 + sdk/go/mssql/schema.go | 298 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 sdk/go/mssql/schema.go diff --git a/.gitignore b/.gitignore index 9ba2218..784ad1c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ yarn.lock **/pulumiManifest.go ci-scripts -**/schema.go +provider/**/schema.go provider/**/schema-embed.json **/version.txt **/nuget diff --git a/go.work.sum b/go.work.sum index b1142c7..7ca8d39 100644 --- a/go.work.sum +++ b/go.work.sum @@ -160,6 +160,8 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 github.com/hashicorp/terraform-exec v0.9.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= github.com/hashicorp/terraform-json v0.5.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= +github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ= +github.com/hashicorp/terraform-plugin-framework-validators v0.10.0/go.mod h1:qdQJCdimB9JeX2YwOpItEu+IrfoJjWQ5PhLpAOMDQAE= github.com/hashicorp/terraform-plugin-go v0.14.1/go.mod h1:Bc/K6K26BQ2FHqIELPbpKtt2CzzbQou+0UQF3/0NsCQ= github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= github.com/hashicorp/terraform-plugin-sdk v1.7.0/go.mod h1:OjgQmey5VxnPej/buEhe+YqKm0KNvV3QqU4hkqHqPCY= @@ -192,6 +194,8 @@ github.com/moby/moby v23.0.0+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHs github.com/mxschmitt/golang-combinations v1.0.0/go.mod h1:RbMhWvfCelHR6WROvT2bVfxJvZHoEvBj71SKe+H0MYU= github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI= +github.com/pgavlin/diff v0.0.0-20230503175810-113847418e2e/go.mod h1:WGwlmuPAiQTGQUjxyAfP7j4JgbgiFvFpI/qRtsQtS/4= +github.com/pgavlin/text v0.0.0-20230428184845-84c285f11d2f/go.mod h1:fk4+YyTLi0Ap0CsL1HA70/tAs6evqw3hbPGdR8rD/3E= github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/pulumi/pulumi-java/pkg v0.8.0 h1:b81/D/dk5/9OEH1k5BJxhqYiQc7Y4TPDbHVGBvJU1GE= @@ -214,6 +218,7 @@ github.com/pulumi/pulumi/sdk/v3 v3.62.0/go.mod h1:Pb5H3OaRZg0n4TRIfY0pagR/NBIEvj github.com/pulumi/terraform-diff-reader v0.0.0-20201211191010-ad4715e9285e/go.mod h1:sZ9FUzGO+yM41hsQHs/yIcj/Y993qMdBxBU5mpDmAfQ= github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil/v3 v3.22.3/go.mod h1:D01hZJ4pVHPpCTZ3m3T2+wDF2YAGfd+H4ifUguaQzHM= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= diff --git a/sdk/go/mssql/schema.go b/sdk/go/mssql/schema.go new file mode 100644 index 0000000..18a6491 --- /dev/null +++ b/sdk/go/mssql/schema.go @@ -0,0 +1,298 @@ +// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. +// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** + +package mssql + +import ( + "context" + "reflect" + + "errors" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +// Manages single DB schema. +// +// ## Example Usage +// +// ```go +// package main +// +// import ( +// +// "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +// "github.com/pulumiverse/pulumi-mssql/sdk/go/mssql" +// +// ) +// +// func main() { +// pulumi.Run(func(ctx *pulumi.Context) error { +// exampleDatabase, err := mssql.LookupDatabase(ctx, &mssql.LookupDatabaseArgs{ +// Name: "example", +// }, nil) +// if err != nil { +// return err +// } +// owner, err := mssql.LookupSqlUser(ctx, &mssql.LookupSqlUserArgs{ +// Name: "example_user", +// }, nil) +// if err != nil { +// return err +// } +// _, err = mssql.NewSchema(ctx, "exampleSchema", &mssql.SchemaArgs{ +// Name: pulumi.String("example"), +// DatabaseId: *pulumi.String(exampleDatabase.Id), +// OwnerId: *pulumi.String(owner.Id), +// }) +// if err != nil { +// return err +// } +// return nil +// }) +// } +// +// ``` +// +// ## Import +// +// import using / - can be retrieved using `SELECT CONCAT(DB_ID(), '/', SCHEMA_ID(''))` +// +// ```sh +// +// $ pulumi import mssql:index/schema:Schema example '7/5' +// +// ``` +type Schema struct { + pulumi.CustomResourceState + + // ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. + DatabaseId pulumi.StringOutput `pulumi:"databaseId"` + // Schema name. + Name pulumi.StringOutput `pulumi:"name"` + // ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` + OwnerId pulumi.StringOutput `pulumi:"ownerId"` +} + +// NewSchema registers a new resource with the given unique name, arguments, and options. +func NewSchema(ctx *pulumi.Context, + name string, args *SchemaArgs, opts ...pulumi.ResourceOption) (*Schema, error) { + if args == nil { + return nil, errors.New("missing one or more required arguments") + } + + if args.Name == nil { + return nil, errors.New("invalid value for required argument 'Name'") + } + opts = pkgResourceDefaultOpts(opts) + var resource Schema + err := ctx.RegisterResource("mssql:index/schema:Schema", name, args, &resource, opts...) + if err != nil { + return nil, err + } + return &resource, nil +} + +// GetSchema gets an existing Schema resource's state with the given name, ID, and optional +// state properties that are used to uniquely qualify the lookup (nil if not required). +func GetSchema(ctx *pulumi.Context, + name string, id pulumi.IDInput, state *SchemaState, opts ...pulumi.ResourceOption) (*Schema, error) { + var resource Schema + err := ctx.ReadResource("mssql:index/schema:Schema", name, id, state, &resource, opts...) + if err != nil { + return nil, err + } + return &resource, nil +} + +// Input properties used for looking up and filtering Schema resources. +type schemaState struct { + // ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. + DatabaseId *string `pulumi:"databaseId"` + // Schema name. + Name *string `pulumi:"name"` + // ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` + OwnerId *string `pulumi:"ownerId"` +} + +type SchemaState struct { + // ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. + DatabaseId pulumi.StringPtrInput + // Schema name. + Name pulumi.StringPtrInput + // ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` + OwnerId pulumi.StringPtrInput +} + +func (SchemaState) ElementType() reflect.Type { + return reflect.TypeOf((*schemaState)(nil)).Elem() +} + +type schemaArgs struct { + // ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. + DatabaseId *string `pulumi:"databaseId"` + // Schema name. + Name string `pulumi:"name"` + // ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` + OwnerId *string `pulumi:"ownerId"` +} + +// The set of arguments for constructing a Schema resource. +type SchemaArgs struct { + // ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. + DatabaseId pulumi.StringPtrInput + // Schema name. + Name pulumi.StringInput + // ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` + OwnerId pulumi.StringPtrInput +} + +func (SchemaArgs) ElementType() reflect.Type { + return reflect.TypeOf((*schemaArgs)(nil)).Elem() +} + +type SchemaInput interface { + pulumi.Input + + ToSchemaOutput() SchemaOutput + ToSchemaOutputWithContext(ctx context.Context) SchemaOutput +} + +func (*Schema) ElementType() reflect.Type { + return reflect.TypeOf((**Schema)(nil)).Elem() +} + +func (i *Schema) ToSchemaOutput() SchemaOutput { + return i.ToSchemaOutputWithContext(context.Background()) +} + +func (i *Schema) ToSchemaOutputWithContext(ctx context.Context) SchemaOutput { + return pulumi.ToOutputWithContext(ctx, i).(SchemaOutput) +} + +// SchemaArrayInput is an input type that accepts SchemaArray and SchemaArrayOutput values. +// You can construct a concrete instance of `SchemaArrayInput` via: +// +// SchemaArray{ SchemaArgs{...} } +type SchemaArrayInput interface { + pulumi.Input + + ToSchemaArrayOutput() SchemaArrayOutput + ToSchemaArrayOutputWithContext(context.Context) SchemaArrayOutput +} + +type SchemaArray []SchemaInput + +func (SchemaArray) ElementType() reflect.Type { + return reflect.TypeOf((*[]*Schema)(nil)).Elem() +} + +func (i SchemaArray) ToSchemaArrayOutput() SchemaArrayOutput { + return i.ToSchemaArrayOutputWithContext(context.Background()) +} + +func (i SchemaArray) ToSchemaArrayOutputWithContext(ctx context.Context) SchemaArrayOutput { + return pulumi.ToOutputWithContext(ctx, i).(SchemaArrayOutput) +} + +// SchemaMapInput is an input type that accepts SchemaMap and SchemaMapOutput values. +// You can construct a concrete instance of `SchemaMapInput` via: +// +// SchemaMap{ "key": SchemaArgs{...} } +type SchemaMapInput interface { + pulumi.Input + + ToSchemaMapOutput() SchemaMapOutput + ToSchemaMapOutputWithContext(context.Context) SchemaMapOutput +} + +type SchemaMap map[string]SchemaInput + +func (SchemaMap) ElementType() reflect.Type { + return reflect.TypeOf((*map[string]*Schema)(nil)).Elem() +} + +func (i SchemaMap) ToSchemaMapOutput() SchemaMapOutput { + return i.ToSchemaMapOutputWithContext(context.Background()) +} + +func (i SchemaMap) ToSchemaMapOutputWithContext(ctx context.Context) SchemaMapOutput { + return pulumi.ToOutputWithContext(ctx, i).(SchemaMapOutput) +} + +type SchemaOutput struct{ *pulumi.OutputState } + +func (SchemaOutput) ElementType() reflect.Type { + return reflect.TypeOf((**Schema)(nil)).Elem() +} + +func (o SchemaOutput) ToSchemaOutput() SchemaOutput { + return o +} + +func (o SchemaOutput) ToSchemaOutputWithContext(ctx context.Context) SchemaOutput { + return o +} + +// ID of database. Can be retrieved using `Database` or `SELECT DB_ID('')`. Defaults to ID of `master`. +func (o SchemaOutput) DatabaseId() pulumi.StringOutput { + return o.ApplyT(func(v *Schema) pulumi.StringOutput { return v.DatabaseId }).(pulumi.StringOutput) +} + +// Schema name. +func (o SchemaOutput) Name() pulumi.StringOutput { + return o.ApplyT(func(v *Schema) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput) +} + +// ID of database role or user owning this schema. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal` +func (o SchemaOutput) OwnerId() pulumi.StringOutput { + return o.ApplyT(func(v *Schema) pulumi.StringOutput { return v.OwnerId }).(pulumi.StringOutput) +} + +type SchemaArrayOutput struct{ *pulumi.OutputState } + +func (SchemaArrayOutput) ElementType() reflect.Type { + return reflect.TypeOf((*[]*Schema)(nil)).Elem() +} + +func (o SchemaArrayOutput) ToSchemaArrayOutput() SchemaArrayOutput { + return o +} + +func (o SchemaArrayOutput) ToSchemaArrayOutputWithContext(ctx context.Context) SchemaArrayOutput { + return o +} + +func (o SchemaArrayOutput) Index(i pulumi.IntInput) SchemaOutput { + return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Schema { + return vs[0].([]*Schema)[vs[1].(int)] + }).(SchemaOutput) +} + +type SchemaMapOutput struct{ *pulumi.OutputState } + +func (SchemaMapOutput) ElementType() reflect.Type { + return reflect.TypeOf((*map[string]*Schema)(nil)).Elem() +} + +func (o SchemaMapOutput) ToSchemaMapOutput() SchemaMapOutput { + return o +} + +func (o SchemaMapOutput) ToSchemaMapOutputWithContext(ctx context.Context) SchemaMapOutput { + return o +} + +func (o SchemaMapOutput) MapIndex(k pulumi.StringInput) SchemaOutput { + return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Schema { + return vs[0].(map[string]*Schema)[vs[1].(string)] + }).(SchemaOutput) +} + +func init() { + pulumi.RegisterInputType(reflect.TypeOf((*SchemaInput)(nil)).Elem(), &Schema{}) + pulumi.RegisterInputType(reflect.TypeOf((*SchemaArrayInput)(nil)).Elem(), SchemaArray{}) + pulumi.RegisterInputType(reflect.TypeOf((*SchemaMapInput)(nil)).Elem(), SchemaMap{}) + pulumi.RegisterOutputType(SchemaOutput{}) + pulumi.RegisterOutputType(SchemaArrayOutput{}) + pulumi.RegisterOutputType(SchemaMapOutput{}) +} From 419212421b7a993811024372229a12a616264737 Mon Sep 17 00:00:00 2001 From: Thomas Meckel Date: Tue, 13 Jun 2023 18:42:16 +0000 Subject: [PATCH 2/4] Added documentation how to configure the provider docs/installation-configuration.md --- docs/installation-configuration.md | 241 +++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) diff --git a/docs/installation-configuration.md b/docs/installation-configuration.md index 9408700..b0077e6 100644 --- a/docs/installation-configuration.md +++ b/docs/installation-configuration.md @@ -13,6 +13,247 @@ The Pulumi MSSQL provider is available as a package in all Pulumi languages: * Go: [`github.com/pulumiverse/pulumi-mssql/sdk/go/mssql`](https://pkg.go.dev/github.com/pulumiverse/pulumi-mssql/sdk/go/mssql) * .NET: [`Pulumiverse.Mssql`](https://www.nuget.org/packages/Pulumiverse.Mssql) +### Authentication Methods + +#### SQL auth + +Provider username and password, using `sql_auth` field: + +{{< chooser language "typescript,python,go,csharp,yaml" >}} + +{{% choosable language typescript %}} +```typescript +const providerMssql = new mssql.Provider("provider-mssql", { + hostname: "localhost", + port: 1433, + sqlAuth: { + username: "sa", + password: "sa_password", + }, +}); +``` +{{% /choosable %}} + +{{% choosable language python %}} +```python +provider_mssql = mssql.Provider("provider-mssql", + hostname="localhost", + port=1433, + sql_auth=mssql.ProviderSqlAuthArgs( + username="sa", + password="sa_password", + )) +``` +{{% /choosable %}} + +{{% choosable language go %}} +```go +_, err := mssql.NewProvider(ctx, "provider-mssql", &mssql.ProviderArgs{ + Hostname: pulumi.String("localhost"), + Port: pulumi.Int(1433), + SqlAuth: &mssql.ProviderSqlAuthArgs{ + Username: pulumi.String("sa"), + Password: pulumi.String("sa_password"), + }, +}) +if err != nil { + return err +} +``` +{{% /choosable %}} + +{{% choosable language csharp %}} +```csharp +var providerMssql = new Mssql.Provider("provider-mssql", new() +{ + Hostname = "localhost", + Port = 1433, + SqlAuth = new Mssql.Inputs.ProviderSqlAuthArgs + { + Username = "sa", + Password = "sa_password", + }, +}); +``` +{{% /choosable %}} + +{{% choosable language yaml %}} +```yaml +resources: + provider-mssql: + type: pulumi:providers:mssql + properties: + hostname: "localhost" + port: 1433 + sqlAuth: + username: "sa" + password: "sa_password" +``` +{{% /choosable %}} + +{{< /chooser >}} + +#### Azure AD +In case of Azure SQL connections, Azure Active Directory auth tokens can be used to authenticate. + +##### Service Principal + +Provide client ID (a.k.a. application ID), secret and tenant ID, using `azure_auth` field: + +{{< chooser language "typescript,python,go,csharp,yaml" >}} + +{{% choosable language typescript %}} +```typescript +const providerMssql = new mssql.Provider("provider-mssql", { + hostname: "example.database.windows.net", + port: 1433, + azureAuth: { + clientId: "94e8d55d-cbbc-4e41-b21a-8923d83f9a85", + clientSecret: "client_secret", + tenantId: "a352c914-bfd9-4b7e-8b1d-554a58353f22", + }, +}); +``` +{{% /choosable %}} + +{{% choosable language python %}} +```python +provider_mssql = mssql.Provider("provider-mssql", + hostname="example.database.windows.net", + port=1433, + azure_auth=mssql.ProviderAzureAuthArgs( + client_id="94e8d55d-cbbc-4e41-b21a-8923d83f9a85", + client_secret="client_secret", + tenant_id="a352c914-bfd9-4b7e-8b1d-554a58353f22", + )) +``` +{{% /choosable %}} + +{{% choosable language go %}} +```go +_, err := mssql.NewProvider(ctx, "provider-mssql", &mssql.ProviderArgs{ + Hostname: pulumi.String("example.database.windows.net"), + Port: pulumi.Int(1433), + AzureAuth: &mssql.ProviderAzureAuthArgs{ + ClientId: pulumi.String("94e8d55d-cbbc-4e41-b21a-8923d83f9a85"), + ClientSecret: pulumi.String("client_secret"), + TenantId: pulumi.String("a352c914-bfd9-4b7e-8b1d-554a58353f22"), + }, +}) +if err != nil { + return err +} +return nil +``` +{{% /choosable %}} + +{{% choosable language csharp %}} +```csharp +var providerMssql = new Mssql.Provider("provider-mssql", new() +{ + Hostname = "example.database.windows.net", + Port = 1433, + AzureAuth = new Mssql.Inputs.ProviderAzureAuthArgs + { + ClientId = "94e8d55d-cbbc-4e41-b21a-8923d83f9a85", + ClientSecret = "client_secret", + TenantId = "a352c914-bfd9-4b7e-8b1d-554a58353f22", + }, +}); +``` +{{% /choosable %}} + +{{% choosable language yaml %}} +```yaml +resources: + provider-mssql: + type: pulumi:providers:mssql + properties: + hostname: "example.database.windows.net" + port: 1433 + azureAuth: + clientId: "94e8d55d-cbbc-4e41-b21a-8923d83f9a85" + clientSecret: "client_secret" + tenantId: "a352c914-bfd9-4b7e-8b1d-554a58353f22" +``` +{{% /choosable %}} + +{{< /chooser >}} + +##### Default chained credentials + +When `azure_auth` value is set to empty object (`{}`), the provider uses chained credentials built from `EnvironmentCredential` -> `ManagedIdentityCredential` -> `AzureCLICredential`. +See [DefaultAzureCredential docs](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#configure-defaultazurecredential) for details. + +##### Environment variables + +When `azure_auth` value is set to empty object (`{}`) and following environment variables are set, the env variable values will be used for authentication, taking precedence over `DefaultAzureCredential`. + +- `ARM_CLIENT_ID` or `AZURE_CLIENT_ID` +- `ARM_CLIENT_SECRET`or `AZURE_CLIENT_SECRET` +- `ARM_TENANT_ID`or `AZURE_TENANT_ID` + +{{< chooser language "typescript,python,go,csharp,yaml" >}} + +{{% choosable language typescript %}} +```typescript +const providerMssql = new mssql.Provider("provider-mssql", { + hostname: "example.database.windows.net", + port: 1433, + azureAuth: {}, +}); +``` +{{% /choosable %}} + +{{% choosable language python %}} +```python +provider_mssql = mssql.Provider("provider-mssql", + hostname="example.database.windows.net", + port=1433, + azure_auth=mssql.ProviderAzureAuthArgs()) +``` +{{% /choosable %}} + +{{% choosable language go %}} +```go +_, err := mssql.NewProvider(ctx, "provider-mssql", &mssql.ProviderArgs{ + Hostname: pulumi.String("example.database.windows.net"), + Port: pulumi.Int(1433), + AzureAuth: AzureAuth: mssql.ProviderAzureAuthArgs{}, +}) +if err != nil { + return err +} +return nil +}) +``` +{{% /choosable %}} + +{{% choosable language csharp %}} +```csharp +var providerMssql = new Mssql.Provider("provider-mssql", new() +{ + Hostname = "example.database.windows.net", + Port = 1433, + AzureAuth = new Mssql.Inputs.ProviderAzureAuthArgs(), +}); +``` +{{% /choosable %}} + +{{% choosable language yaml %}} +```yaml +resources: + provider-mssql: + type: pulumi:providers:mssql + properties: + hostname: "example.database.windows.net" + port: 1433 + azureAuth: {} +``` +{{% /choosable %}} + +{{< /chooser >}} + ### Provider Binary The MSSQL provider binary is a third party binary. It can be installed using the `pulumi plugin` command. From d513159842ad5cb922b6166129f3c62df78c920b Mon Sep 17 00:00:00 2001 From: Thomas Meckel Date: Tue, 13 Jun 2023 18:42:59 +0000 Subject: [PATCH 3/4] Added examples to docs/_index.md --- docs/_index.md | 501 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 498 insertions(+), 3 deletions(-) diff --git a/docs/_index.md b/docs/_index.md index 8c0af5b..38469ce 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -4,6 +4,501 @@ meta_desc: Provides an overview of the MSSQL Provider for Pulumi. layout: overview --- -The MSSQL provider for Pulumi can be used to provision any of the cloud -resources available in MSSQL.The MSSQL provider must be configured with -credentials to deploy and update resources in MSSQL. +The MSSQL provider for Pulumi can be used to provision and configure objects in +Microsoft SQL Server and Azure SQL instances. The MSSQL provider must be +configured with credentials to deploy and update resources in MSSQL. + + +## Example + +{{< chooser language "typescript,python,go,csharp,yaml" >}} + + +{{% choosable language typescript %}} +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as azure from "@pulumi/azure"; +import * as mssql from "@pulumiverse/mssql"; + +const current = azure.core.getClientConfig({}); + +const resourceGroup = new azure.core.ResourceGroup("resource-group", { + name: "pulumi-mssql-test", + location: "eastus", +}); + +const server = new azure.mssql.Server("server", { + name: "pulumi-mssql-test", + resourceGroupName: resourceGroup.name, + location: resourceGroup.location, + version: "12.0", + minimumTlsVersion: "1.2", + administratorLogin: "sadmin", + administratorLoginPassword: "Str0ngPa$word12", + azureadAdministrator: { + loginUsername: "pulumi-app", + objectId: current.then(current => current.objectId), + tenantId: current.then(current => current.tenantId), + }, +}); + +const databaseFirewallRule = new azure.mssql.FirewallRule("database-firewall-rule", { + name: "azure", + serverId: server.id, + startIpAddress: "0.0.0.0", + endIpAddress: "0.0.0.0", +}); + +const database = new azure.mssql.Database("database", { + name: "db", + serverId: server.id, + licenseType: "LicenseIncluded", + maxSizeGb: 2, + skuName: "Basic", +}); + +const providerMssql = new mssql.Provider("provider-mssql", { + hostname: server.fullyQualifiedDomainName, + azureAuth: {}, +}, { + dependsOn: [ + database, + databaseFirewallRule, + ], +}); + +const databaseId = mssql.getDatabaseOutput({ + name: database.name, +}, { + provider: providerMssql +}); +const databaseRoleOwner = mssql.getDatabaseRoleOutput({ + databaseId: databaseId.id, + name: "db_owner", +}, { + provider: providerMssql +}); + +const dbUser = new mssql.SqlLogin("db-user", { + name: "example", + password: "Str0ngPa$word12", +}, { + provider: providerMssql, +}); +const dbRoleMember = new mssql.DatabaseRoleMember("db-role-member", { + roleId: databaseRoleOwner.id, + memberId: dbUser.id, +}, { + provider: providerMssql, +}); +``` +{{% /choosable %}} + +{{% choosable language python %}} +```python +import pulumi +import pulumi_azure as azure +import pulumiverse_mssql as mssql + +current = azure.core.get_client_config() +resource_group = azure.core.ResourceGroup( + "resource-group", name="pulumi-mssql-test", location="eastus" +) + +server = azure.mssql.Server( + "server", + name="pulumi-mssql-test", + resource_group_name=resource_group.name, + location=resource_group.location, + version="12.0", + minimum_tls_version="1.2", + administrator_login="sadmin", + administrator_login_password="Str0ngPa$word12", + azuread_administrator=azure.mssql.ServerAzureadAdministratorArgs( + login_username="pulumi-app", + object_id=current.object_id, + tenant_id=current.tenant_id, + ), +) + +database = azure.mssql.Database( + "database", + name="db", + server_id=server.id, + license_type="LicenseIncluded", + max_size_gb=2, + sku_name="Basic", +) + +database_firewall_rule = azure.mssql.FirewallRule( + "database-firewall-rule", + name="azure", + server_id=server.id, + start_ip_address="0.0.0.0", + end_ip_address="0.0.0.0", +) + +provider_mssql = mssql.Provider( + "provider-mssql", + hostname=server.fully_qualified_domain_name, + azure_auth=mssql.ProviderAzureAuthArgs(), + opts=pulumi.ResourceOptions( + depends_on=[ + database, + database_firewall_rule, + ] + ), +) + +database_id = mssql.get_database_output( + name=database.name, + opts=pulumi.InvokeOptions(provider=provider_mssql), +) + +database_role_owner = mssql.get_database_role_output( + database_id=database_id.id, + name="db_owner", + opts=pulumi.InvokeOptions(provider=provider_mssql), +) + +db_user = mssql.SqlLogin( + "db-user", + name="example", + password="Str0ngPa$word12", + opts=pulumi.ResourceOptions(provider=provider_mssql), +) + +db_role_member = mssql.DatabaseRoleMember( + "db-role-member", + role_id=database_role_owner.id, + member_id=db_user.id, + opts=pulumi.ResourceOptions(provider=provider_mssql), +) +``` +{{% /choosable %}} + +{{% choosable language go %}} +```go +package main + +import ( + "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core" + azuresql "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/mssql" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/pulumiverse/pulumi-mssql/sdk/go/mssql" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + + current, err := core.GetClientConfig(ctx, nil, nil) + if err != nil { + return err + } + + resourceGroup, err := core.NewResourceGroup(ctx, "resource-group", &core.ResourceGroupArgs{ + Name: pulumi.String("pulumi-mssql-test"), + Location: pulumi.String("eastus"), + }) + if err != nil { + return err + } + + server, err := azuresql.NewServer(ctx, "server", &azuresql.ServerArgs{ + Name: pulumi.String("pulumi-mssql-test"), + ResourceGroupName: resourceGroup.Name, + Location: resourceGroup.Location, + Version: pulumi.String("12.0"), + MinimumTlsVersion: pulumi.String("1.2"), + AdministratorLogin: pulumi.String("sadmin"), + AdministratorLoginPassword: pulumi.String("Str0ngPa$word12"), + AzureadAdministrator: &azuresql.ServerAzureadAdministratorArgs{ + LoginUsername: pulumi.String("pulumi-app"), + ObjectId: pulumi.String(current.ObjectId), + TenantId: pulumi.String(current.TenantId), + }, + }) + if err != nil { + return err + } + + database, err := azuresql.NewDatabase(ctx, "database", &azuresql.DatabaseArgs{ + Name: pulumi.String("db"), + ServerId: server.ID(), + LicenseType: pulumi.String("LicenseIncluded"), + MaxSizeGb: pulumi.Int(2), + SkuName: pulumi.String("Basic"), + }) + if err != nil { + return err + } + + databaseFirewallRule, err := azuresql.NewFirewallRule(ctx, "database-firewall-rule", &azuresql.FirewallRuleArgs{ + Name: pulumi.String("azure"), + ServerId: server.ID(), + StartIpAddress: pulumi.String("0.0.0.0"), + EndIpAddress: pulumi.String("0.0.0.0"), + }) + if err != nil { + return err + } + providerMssql, err := mssql.NewProvider(ctx, "provider-mssql", &mssql.ProviderArgs{ + Hostname: server.FullyQualifiedDomainName, + AzureAuth: mssql.ProviderAzureAuthArgs{}, + }, pulumi.DependsOn([]pulumi.Resource{ + database, + databaseFirewallRule, + })) + if err != nil { + return err + } + + databaseId := mssql.LookupDatabaseOutput(ctx, mssql.LookupDatabaseOutputArgs{ + Name: database.Name, + }, pulumi.Provider(providerMssql)) + + databaseRoleOwner := mssql.LookupDatabaseRoleOutput(ctx, mssql.LookupDatabaseRoleOutputArgs{ + DatabaseId: databaseId.Id(), + Name: pulumi.String("db_owner"), + }, pulumi.Provider(providerMssql)) + + dbUser, err := mssql.NewSqlLogin(ctx, "db-user", &mssql.SqlLoginArgs{ + Name: pulumi.String("example"), + Password: pulumi.String("Str0ngPa$word12"), + }, pulumi.Provider(providerMssql)) + if err != nil { + return err + } + + _, err = mssql.NewDatabaseRoleMember(ctx, "db-role-member", &mssql.DatabaseRoleMemberArgs{ + RoleId: databaseRoleOwner.Id(), + MemberId: dbUser.ID(), + }, pulumi.Provider(providerMssql)) + if err != nil { + return err + } + return nil + }) +} +``` +{{% /choosable %}} + +{{% choosable language csharp %}} +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using Azure = Pulumi.Azure; +using Mssql = Pulumiverse.Mssql; + +return await Deployment.RunAsync(async () => +{ + var current = await Azure.Core.GetClientConfig.InvokeAsync(); + + var resourceGroup = new Azure.Core.ResourceGroup( + "resource-group", + new() { Name = "pulumi-mssql-test", Location = "eastus", } + ); + + var server = new Azure.MSSql.Server( + "server", + new() + { + Name = "pulumi-mssql-test", + ResourceGroupName = resourceGroup.Name, + Location = resourceGroup.Location, + Version = "12.0", + MinimumTlsVersion = "1.2", + AdministratorLogin = "sadmin", + AdministratorLoginPassword = "Str0ngPa$word12", + AzureadAdministrator = new Azure.MSSql.Inputs.ServerAzureadAdministratorArgs + { + LoginUsername = "pulumi-app", + ObjectId = current.ObjectId, + TenantId = current.TenantId, + }, + } + ); + + var database = new Azure.MSSql.Database( + "database", + new() + { + Name = "db", + ServerId = server.Id, + LicenseType = "LicenseIncluded", + MaxSizeGb = 2, + SkuName = "Basic", + } + ); + + var databaseFirewallRule = new Azure.MSSql.FirewallRule( + "database-firewall-rule", + new() + { + Name = "azure", + ServerId = server.Id, + StartIpAddress = "0.0.0.0", + EndIpAddress = "0.0.0.0", + } + ); + + var providerMssql = new Mssql.Provider( + "provider-mssql", + new() + { + Hostname = server.FullyQualifiedDomainName, + AzureAuth = new Mssql.Inputs.ProviderAzureAuthArgs(), + }, + new CustomResourceOptions + { + DependsOn = new Resource[] { database, databaseFirewallRule, }, + } + ); + + var databaseId = Mssql.GetDatabase.Invoke( + new() { Name = database.Name, }, + new InvokeOptions { Provider = providerMssql } + ); + + var databaseRoleOwner = Mssql.GetDatabaseRole.Invoke( + new() + { + DatabaseId = databaseId.Apply(getDatabaseResult => getDatabaseResult.Id), + Name = "db_owner", + }, + new InvokeOptions { Provider = providerMssql } + ); + + var dbUser = new Mssql.SqlLogin( + "db-user", + new() { Name = "example", Password = "Str0ngPa$word12", }, + new CustomResourceOptions { Provider = providerMssql, } + ); + + var dbRoleMember = new Mssql.DatabaseRoleMember( + "db-role-member", + new() + { + RoleId = databaseRoleOwner.Apply(getDatabaseRoleResult => getDatabaseRoleResult.Id), + MemberId = dbUser.Id, + }, + new CustomResourceOptions { Provider = providerMssql, } + ); +}); +``` +{{% /choosable %}} + +{{% choosable language yaml %}} +```yaml +name: mssql-test +runtime: yaml +description: A Pulumi YAML project to test the new MSSQL provider + +variables: + current: + fn::invoke: + function: azure:core:getClientConfig + options: + provider: ${provider} + + database-id: + fn::invoke: + function: mssql:getDatabase + arguments: + name: ${database.name} + options: + provider: ${provider-mssql} + + database-role-owner: + fn::invoke: + function: mssql:getDatabaseRole + arguments: + databaseId: ${database-id.id} + name: "db_owner" + options: + provider: ${provider-mssql} + +outputs: {} + +resources: + provider: + type: pulumi:providers:azure + properties: + skipProviderRegistration: true + options: + version: 5.43.0 + + resource-group: + type: azure:core:ResourceGroup + properties: + name: "pulumi-mssql-test" + location: "eastus" + + server: + type: azure:mssql:Server + properties: + name: "pulumi-mssql-test" + resourceGroupName: ${resource-group.name} + location: ${resource-group.location} + version: '12.0' + minimumTlsVersion: '1.2' + administratorLogin: sadmin + administratorLoginPassword: "Str0ngPa$$word12" + azureadAdministrator: + loginUsername: "pulumi-app" + objectId: ${current.objectId} + tenantId: ${current.tenantId} + options: + provider: ${provider} + + database-firewall-rule: + type: azure:mssql:FirewallRule + properties: + name: azure + serverId: ${server.id} + startIpAddress: "0.0.0.0" + endIpAddress: "0.0.0.0" + options: + provider: ${provider} + + database: + type: azure:mssql:Database + properties: + name: "db" + serverId: ${server.id} + licenseType: LicenseIncluded + maxSizeGb: 2 + skuName: Basic + options: + provider: ${provider} + + provider-mssql: + type: pulumi:providers:mssql + properties: + hostname: ${server.fullyQualifiedDomainName} + azureAuth: {} + options: + dependsOn: + - ${database} + - ${database-firewall-rule} + + db-user: + type: mssql:SqlLogin + properties: + name: example + password: "Str0ngPa$$word12" + options: + provider: ${provider-mssql} + + db-role-member: + type: mssql:DatabaseRoleMember + properties: + roleId: ${database-role-owner.id} + memberId: ${db-user.id} + options: + provider: ${provider-mssql} +``` +{{% /choosable %}} + +{{< /chooser >}} From 0c6837fb588a3a12f49bfd7fc69f84e21ea00087 Mon Sep 17 00:00:00 2001 From: Thomas Meckel Date: Wed, 14 Jun 2023 07:37:36 +0000 Subject: [PATCH 4/4] Changed layout of markdown pages to package for docs/installation-configuration.md and docs/_index.md --- docs/_index.md | 2 +- docs/installation-configuration.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_index.md b/docs/_index.md index 38469ce..eb625ca 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -1,7 +1,7 @@ --- title: MSSQL meta_desc: Provides an overview of the MSSQL Provider for Pulumi. -layout: overview +layout: package --- The MSSQL provider for Pulumi can be used to provision and configure objects in diff --git a/docs/installation-configuration.md b/docs/installation-configuration.md index b0077e6..9cb820c 100644 --- a/docs/installation-configuration.md +++ b/docs/installation-configuration.md @@ -1,7 +1,7 @@ --- title: MSSQL Installation & Configuration meta_desc: Information on how to install the MSSQL provider. -layout: installation +layout: package --- ## Installation