Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
TER-232: First version of a Dockerized build and test environment + f…
Browse files Browse the repository at this point in the history
…ixing dependencies imports and code to allow working build (empty right now)
  • Loading branch information
Benoît OYEZ authored and Shr3ps committed Mar 5, 2018
1 parent 832cceb commit 7451782
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/terraform-*
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ resource "ghost_app" "wordpress" {
}
}
```

# Building and testing in a Dockerized environment #

The dockerized environment can be invoked through docker-compose. It mounts an external volume named _root_user_ in which you can personalize the root session.

Hint: in the _root_user_ volume, you can import your personal SSH keys and add a .gitconfig file with a content like this:
```
[url "[email protected]:"]
insteadOf = https://bitbucket.org/
```
To allow go to load git dependencies from private repositories using your SSH key.

To use the environment, just run the command:
`docker-compose run --rm [test|build]-env` in the root directory of this project.
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

go get .
go build -o "${PWD##*/}"
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '2'

services:
build-env:
image: golang
volumes:
- ./:/go/src/terraform-provider-ghost
- root_user:/root
working_dir: /go/src/terraform-provider-ghost
entrypoint: ./build.sh

test-env:
image: golang
volumes:
- ./:/go/src/terraform-provider-ghost
- root_user:/root
working_dir: /go/src/terraform-provider-ghost
entrypoint: ./test.sh

volumes:
root_user:
external: true
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"bitbucket.org/morea/terraform-provider-ghost/provider"
provider "terraform-provider-ghost/provider"
"github.com/hashicorp/terraform/plugin"
)

Expand Down
6 changes: 5 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func Provider() terraform.ResourceProvider {
}

func providerConfigure(data *schema.ResourceData) (interface{}, error) {
config := Config{User: data.Get("user").(string), Password: data.Get("password").(string), URL: data.Get("endpoint").(string)}
config := Config{
User: data.Get("user").(string),
Password: data.Get("password").(string),
URL: data.Get("endpoint").(string)
}
log.Println("[INFO] Initializing Ghost client")
return config.Client()
}
22 changes: 4 additions & 18 deletions provider/resource_ghost_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ghost
import (
"log"

ghost "bitbucket.org/morea/go-st"
"github.com/hashicorp/terraform/helper/schema"
)

Expand All @@ -13,9 +12,6 @@ func resourceGhostApp() *schema.Resource {
Read: resourceGhostAppRead,
Update: resourceGhostAppUpdate,
Delete: resourceGhostAppDelete,
Importer: &schema.ResourceImporter{
State: resourceGhostAppImport,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand All @@ -31,39 +27,29 @@ func resourceGhostApp() *schema.Resource {
}

func resourceGhostAppCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ghost.Client)
//client := meta.(*ghost.Client)
log.Printf("[INFO] Creating Ghost app %s", d.Get("name").(string))

d.SetId(app.ID)
return nil
}

func resourceGhostAppRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ghost.Client)
//client := meta.(*ghost.Client)
log.Printf("[INFO] Reading Ghost app %s", d.Get("name").(string))
// TODO retrieve Ghost App with d.Id()
d.Set("name", app.Name)

return nil
}

func resourceGhostAppUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ghost.Client)
//client := meta.(*ghost.Client)
log.Printf("[INFO] Updating Ghost app %s", d.Get("name").(string))
return nil
}

func resourceGhostAppDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ghost.Client)
//client := meta.(*ghost.Client)
log.Printf("[INFO] Deleting Ghost app %s", d.Get("name").(string))
d.SetId("")
return nil
}

func resourceGhostAppImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
log.Printf("[INFO] Importing Ghost app %s", d.Get("name").(string))
if err := resourceGhostAppRead(d, meta); err != nil {
return nil, err
}
return []*schema.ResourceData{d}, nil
}
1 change: 0 additions & 1 deletion provider/resource_ghost_app_test.go
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
package ghost
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

go get .
go test

0 comments on commit 7451782

Please sign in to comment.