diff --git a/README.md b/README.md index 5026c34..4421659 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,48 @@ Terraform Provider using the [Microsoft IIS Administration](https://docs.microsoft.com/en-us/IIS-Administration/) API. -## Usage +# Usage + +## Setup + ```hcl provider "iis" { access_key = "your access key" host = "https://localhost:55539" } +``` + +## Application pools +```hcl resource "iis_application_pool" "name" { name = "AppPool" // Name of the Application Pool } +``` + +## Directories -resource "iis_application" "name" { - physical_path = "%systemdrive%\\inetpub\\your_app" // Path on the server to your web app - application_pool = "${iis_application_pool.name.id}" - path = "YourApp" // Path for URL access - website = "${data.iis_website.default.ids[0]}" // id for the website is required +```hcl +resource "iis_file" "name" { + name = "name.of.your.directory" + physical_path = "%systemdrive%\\inetpub\\your_app" // full path to directory + type = "directory" // can also be "file" + parent = "parent_id" // id of the parent folder } +``` + +## Websites -data "iis_website" "default" {} -``` \ No newline at end of file +```hcl +data "iis_website" "website-domain-com" { + name = "website.domain.com" + physical_path = "%systemdrive%\\inetpub\\your_app" // full path to website folder + application_pool = iis_application_pool.name.id + binding { + protocol = "http" + port = 80 + ip_address = "*" + hostname = "website.domain.com" + } +} +``` diff --git a/go.mod b/go.mod index 7f14721..6e996dc 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/maxjoehnk/terraform-provider-iis +module github.com/nrgribeiro/terraform-provider-iis go 1.15 diff --git a/go.sum b/go.sum index 0e91b02..4b26897 100644 --- a/go.sum +++ b/go.sum @@ -206,8 +206,6 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/maxjoehnk/microsoft-iis-administration v0.0.0-20201113134626-dac6f1adc02f h1:WhPrsY6OKWoLXACaMQ4geNH4UU+9FOw5t2zW8xWaSbE= -github.com/maxjoehnk/microsoft-iis-administration v0.0.0-20201113134626-dac6f1adc02f/go.mod h1:RvSyx6SPV+AkzVjVK08vD1VvJ4Hgas/o31yCOesK+hA= github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= diff --git a/iis/provider.go b/iis/provider.go index 91b67b8..795ca84 100644 --- a/iis/provider.go +++ b/iis/provider.go @@ -24,6 +24,7 @@ func Provider() *schema.Provider { "iis_application": resourceApplication(), "iis_authentication": resourceAuthentication(), "iis_website": resourceWebsite(), + "iis_file": resourceFile(), }, DataSourcesMap: map[string]*schema.Resource{ "iis_website": dataSourceIisWebsite(), diff --git a/iis/resource_application_pool.go b/iis/resource_application_pool.go index eb0eb01..05d1913 100644 --- a/iis/resource_application_pool.go +++ b/iis/resource_application_pool.go @@ -26,7 +26,7 @@ func resourceApplicationPool() *schema.Resource { ManagedRuntimeKey: { Type: schema.TypeString, Optional: true, - Default: "", + Default: "", }, StatusKey: { Type: schema.TypeString, diff --git a/iis/resource_file.go b/iis/resource_file.go new file mode 100644 index 0000000..6435416 --- /dev/null +++ b/iis/resource_file.go @@ -0,0 +1,102 @@ +package iis + +import ( + "context" + "github.com/nrgribeiro/microsoft-iis-administration" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +const fileNameKey = "name" +const filePhysicalPathKey = "physical_path" +const typeKey = "type" +const parentKey = "parent" + +func resourceFile() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceFileCreate, + ReadContext: resourceFileRead, + UpdateContext: resourceFileUpdate, + DeleteContext: resourceFileDelete, + + Schema: map[string]*schema.Schema{ + fileNameKey: { + Type: schema.TypeString, + Required: true, + }, + filePhysicalPathKey: { + Type: schema.TypeString, + Required: true, + }, + typeKey: { + Type: schema.TypeString, + Required: true, + }, + parentKey: { + Type: schema.TypeString, + Required: true, + }, + }, + } +} + +func resourceFileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + client := m.(*iis.Client) + request := createFileRequest(d) + site, err := client.CreateFile(ctx, request) + if err != nil { + return diag.FromErr(err) + } + d.SetId(site.ID) + return nil +} + +func resourceFileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + client := m.(*iis.Client) + site, err := client.ReadFile(ctx, d.Id()) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + if err = d.Set(nameKey, site.Name); err != nil { + return diag.FromErr(err) + } + if err = d.Set(physicalPathKey, site.PhysicalPath); err != nil { + return diag.FromErr(err) + } + if err = d.Set(typeKey, site.Type); err != nil { + return diag.FromErr(err) + } + return nil +} + +func resourceFileUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + return nil +} + +func resourceFileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + client := m.(*iis.Client) + id := d.Id() + err := client.DeleteFile(ctx, id) + if err != nil { + return diag.FromErr(err) + } + return nil +} + +func createFileRequest(d *schema.ResourceData) iis.CreateFileRequest { + name := d.Get(nameKey).(string) + physicalPath := d.Get(physicalPathKey).(string) + parentId := d.Get(parentKey).(string) + typeName := d.Get(typeKey).(string) + request := iis.CreateFileRequest{ + Name: name, + PhysicalPath: physicalPath, + Parent: iis.FileParent{ + Id: parentId, + }, + Type: typeName, + } + + return request +} diff --git a/iis/resource_website.go b/iis/resource_website.go index 870aaf3..bb44e50 100644 --- a/iis/resource_website.go +++ b/iis/resource_website.go @@ -2,9 +2,9 @@ package iis import ( "context" + "github.com/nrgribeiro/microsoft-iis-administration" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/nrgribeiro/microsoft-iis-administration" ) const nameKey = "name" diff --git a/main.go b/main.go index d16615f..25de99f 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ package main import ( "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "github.com/maxjoehnk/terraform-provider-iis/iis" + "github.com/nrgribeiro/terraform-provider-iis/iis" ) func main() {