Skip to content

Commit

Permalink
fix: application pool with managed runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgribeiro committed Apr 29, 2021
2 parents 5dfbba5 + deaeaa3 commit ea458b8
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 14 deletions.
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}
```
```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"
}
}
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/maxjoehnk/terraform-provider-iis
module github.com/nrgribeiro/terraform-provider-iis

go 1.15

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions iis/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion iis/resource_application_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func resourceApplicationPool() *schema.Resource {
ManagedRuntimeKey: {
Type: schema.TypeString,
Optional: true,
Default: "",
Default: "",
},
StatusKey: {
Type: schema.TypeString,
Expand Down
102 changes: 102 additions & 0 deletions iis/resource_file.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion iis/resource_website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ea458b8

Please sign in to comment.