forked from claranet/terraform-provider-clouddeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in TER-233-project-structure (pull request #2)
TER-233 provider configuration Approved-by: Patrick Decat <[email protected]> Approved-by: Jordan Caussat <[email protected]> Approved-by: Jérôme Respaut <[email protected]>
- Loading branch information
Showing
1,405 changed files
with
434,466 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ignored/ | ||
/build/terraform* | ||
bin/** | ||
**/*.tfvars |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
SOURCEDIR=. | ||
SOURCES := $(shell find $(SOURCEDIR) -name '*.go' | grep -v vendor) | ||
TEST?=./... | ||
BIN_FOLDER=bin/ | ||
BINARY=$(BIN_FOLDER)terraform-provider-ghost | ||
VERSION=1.0.0 | ||
BUILD_TIME=`date +%FT%T%z` | ||
|
||
default: $(BINARY) | ||
|
||
$(BINARY): $(SOURCES) | ||
go build ${LDFLAGS} -o ${BINARY} main.go | ||
|
||
install: fmt | ||
go install | ||
|
||
fmt: | ||
gofmt -w $(SOURCES) | ||
|
||
test: | ||
go test $(TEST) -timeout=30s -parallel=4 | ||
|
||
testacc: | ||
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m | ||
|
||
vet: | ||
@echo "go vet ." | ||
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ | ||
echo ""; \ | ||
echo "Vet found suspicious constructs. Please check the reported constructs"; \ | ||
echo "and fix them if necessary before submitting the code for review."; \ | ||
exit 1; \ | ||
fi | ||
|
||
vendor-status: | ||
@govendor status | ||
|
||
clean: | ||
$(RM) ${BINARY} | ||
|
||
.PHONY: install fmt test testacc vet vendor-status clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,72 @@ | ||
# Terraform provider that manages Ghost apps # | ||
Terraform Provider that manages Ghost apps | ||
========================================== | ||
|
||
TF example: | ||
Requirements | ||
------------ | ||
|
||
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x | ||
- [Go](https://golang.org/doc/install) 1.9 (to build the provider plugin) | ||
|
||
Bulding The Provider | ||
-------------------- | ||
Clone repository to: `$GOPATH/src/cloud-deploy.io/terraform-provider-ghost` | ||
|
||
Using Go: | ||
```sh | ||
$ go get -d cloud-deploy.io/terraform-provider-ghost | ||
``` | ||
|
||
Using git: | ||
```sh | ||
$ mkdir -p $GOPATH/src/cloud-deploy.io; cd $GOPATH/src/cloud-deploy.io | ||
$ git clone [email protected]:morea/terraform-provider-ghost.git | ||
``` | ||
|
||
Enter the repository and build the provider | ||
```sh | ||
$ cd $GOPATH/src/cloud-deploy.io/terraform-provider-ghost | ||
make | ||
``` | ||
|
||
Using the provider | ||
---------------------- | ||
If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it. | ||
|
||
An example is available in the examples directory. | ||
|
||
Developing the Provider | ||
--------------------------- | ||
|
||
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.9+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. | ||
|
||
To compile the provider, run `make install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. | ||
|
||
In order to test the provider, you can simply run `make test`. | ||
|
||
In order to run the full suite of Acceptance tests, run `make testacc`. | ||
|
||
*Note:* Acceptance tests create real resources. For the tests to pass, you'll need to setup a ghost instance (can be local), and set the following environment variables: | ||
|
||
```sh | ||
$ export GHOST_USER=myuser | ||
$ export GHOST_PASSWORD=mypwd | ||
$ export GHOST_ENDPOINT=http://localhost | ||
|
||
$ make testacc | ||
``` | ||
|
||
TF example: | ||
----------- | ||
``` | ||
provider "ghost" { | ||
user = "admin" | ||
password = "mypass" | ||
endpoint = "https://demo.ghost.morea.fr" | ||
} | ||
resource "ghost_app" "wordpress" { | ||
resource "ghost_app" "test" { | ||
name = "wordpress" | ||
env = "prod" | ||
env = "dev" | ||
role = "webfront" | ||
region = "eu-west-1" | ||
|
@@ -41,48 +96,21 @@ resource "ghost_app" "wordpress" { | |
name = "" | ||
} | ||
module = { | ||
modules = [{ | ||
name = "symfony2" | ||
pre_deploy = "ZXhpdCAx" | ||
path = "/var/www" | ||
scope = "code" | ||
git_repo = "https://github.com/KnpLabs/KnpIpsum.git" | ||
} | ||
}] | ||
feature = { | ||
features = [{ | ||
version = "5.4" | ||
name = "php5" | ||
} | ||
feature = { | ||
}, | ||
{ | ||
version = "2.2" | ||
name = "apache2" | ||
} | ||
} | ||
``` | ||
|
||
# Building and testing in a Dockerized environment # | ||
|
||
The dockerized environment can be invoked through docker-compose. It mounts an external volume named _terraform-provider-ghost-root_user_ in which you can personalize the root session. | ||
|
||
Hint: in the _terraform-provider-ghost-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. | ||
|
||
# Running terraform in a Dockerized environment # | ||
|
||
To run the provider after building, just run the command: | ||
`docker-compose run --rm terraform [plan|<terraform command>]` in the root directory of this project | ||
|
||
the _sources/build_ directory is mounted directly in the container and should be linked by a _.terraformrc_ file in the _terraform-provider-ghost-root_user_ volume, example: | ||
``` | ||
providers { | ||
ghost = "/terraform-providers/ghost/terraform-provider-ghost" | ||
}] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
image: golang:1.10 | ||
|
||
pipelines: | ||
default: | ||
- step: | ||
script: | ||
- PACKAGE_PATH="${GOPATH}/src/cloud-deploy.io/${BITBUCKET_REPO_SLUG}" | ||
- mkdir -pv "${PACKAGE_PATH}" | ||
- tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${PACKAGE_PATH}" | ||
- cd "${PACKAGE_PATH}" | ||
- go get github.com/kardianos/govendor | ||
- make test | ||
- make vendor-status | ||
- make vet |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
variable "password" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
provider "ghost" { | ||
user = "demo" | ||
password = "${var.password}" | ||
endpoint = "https://demo.ghost.morea.fr" | ||
} | ||
|
||
resource "ghost_app" "test" { | ||
name = "wordpress" | ||
env = "dev" | ||
role = "webfront" | ||
|
||
region = "eu-west-1" | ||
instance_type = "t2.micro" | ||
vpc_id = "vpc-3f1eb65a" | ||
|
||
log_notifications = [ | ||
"[email protected]", | ||
] | ||
|
||
build_infos = { | ||
subnet_id = "subnet-a7e849fe" | ||
ssh_username = "admin" | ||
source_ami = "ami-03ce4474" | ||
} | ||
|
||
environment_infos = { | ||
instance_profile = "iam.ec2.demo" | ||
key_name = "ghost-demo" | ||
root_block_device = {} | ||
optional_volumes = [] | ||
subnet_ids = ["subnet-a7e849fe"] | ||
security_groups = ["sg-6814f60c"] | ||
} | ||
|
||
autoscale = { | ||
name = "" | ||
} | ||
|
||
modules = [{ | ||
name = "symfony2" | ||
pre_deploy = "ZXhpdCAx" | ||
path = "/var/www" | ||
scope = "code" | ||
git_repo = "https://github.com/KnpLabs/KnpIpsum.git" | ||
}] | ||
|
||
features = [{ | ||
version = "5.4" | ||
name = "php5" | ||
}, | ||
{ | ||
version = "2.2" | ||
name = "apache2" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ghost | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/url" | ||
|
||
"cloud-deploy.io/go-st" | ||
) | ||
|
||
// Config defines the configuration options for the Ghost client | ||
type Config struct { | ||
User string | ||
Password string | ||
URL string | ||
} | ||
|
||
// Client returns a new Ghost client | ||
func (c *Config) Client() (*ghost.Client, error) { | ||
if c.Password == "" || c.User == "" || c.URL == "" { | ||
return nil, fmt.Errorf(`At least 1 ghost parameter is empty: Username: %s, | ||
Password, URL: %s`, c.User, c.URL) | ||
} | ||
|
||
if _, err := url.ParseRequestURI(c.URL); err != nil { | ||
return nil, fmt.Errorf("Invalid endpoint URL") | ||
} | ||
|
||
client := ghost.NewClient(c.URL, c.User, c.Password) | ||
|
||
log.Printf("[INFO] Ghost client configured: %s %s", c.User, c.URL) | ||
|
||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ghost | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// Test config with empty parameters | ||
func TestConfigEmptyParameters(t *testing.T) { | ||
config := Config{ | ||
User: "", | ||
Password: "", | ||
URL: "", | ||
} | ||
|
||
if _, err := config.Client(); err == nil { | ||
t.Fatalf("expected error, but got nil") | ||
} | ||
} | ||
|
||
// Test config with invalid url | ||
func TestConfigInvalidUrl(t *testing.T) { | ||
config := Config{ | ||
User: "myuser", | ||
Password: "mypwd", | ||
URL: "invalid.url", | ||
} | ||
|
||
if _, err := config.Client(); err == nil { | ||
t.Fatalf("expected error, but got nil") | ||
} | ||
} | ||
|
||
// Test config with valid parameters | ||
func TestConfigValidParameters(t *testing.T) { | ||
config := Config{ | ||
User: "myuser", | ||
Password: "mypwd", | ||
URL: "https://www.valid.url", | ||
} | ||
|
||
if _, err := config.Client(); err != nil { | ||
t.Fatalf("expected no error, but got %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.