Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
griff committed Oct 10, 2016
1 parent 0ab318d commit 5ddd7c8
Show file tree
Hide file tree
Showing 12 changed files with 2,390 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform.tfstate*
terraform-provider-teamcity

61 changes: 61 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"errors"
"github.com/umweltdk/teamcity/teamcity"
"os"
)

type Config struct {
User string
Password string
URL string
Insecure bool
SkipCredsValidation bool
}

func (c *Config) Client() (interface{}, error) {
if c.User == "" {
c.User = os.Getenv("TEAMCITY_USER")
}
if c.User == "" {
return nil, errors.New("Missing TeamCity user and TEAMCITY_USER not defined")
}

if c.Password == "" {
c.Password = os.Getenv("TEAMCITY_PASSWORD")
}
if c.Password == "" {
return nil, errors.New("Missing TeamCity password and TEAMCITY_PASSWORD not defined")
}

if c.URL == "" {
c.URL = os.Getenv("TEAMCITY_URL")
}
if c.URL == "" {
return nil, errors.New("Missing TeamCity URL and TEAMCITY_URL not defined")
}

client := teamcity.New(c.URL, c.User, c.Password)

if !c.SkipCredsValidation {
err := c.ValidateCredentials(client)
if err != nil {
return nil, err
}
}

return client, nil
}

// Validate credentials early and fail before we do any graph walking.
func (c *Config) ValidateCredentials(client *teamcity.Client) error {
server, err := client.Server()
if err != nil {
return err
}
if server == nil {
return errors.New("Received no reply from server")
}
return nil
}
12 changes: 12 additions & 0 deletions examples/hive.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "aws_elastic_beanstalk_application" "hive" {
name = "umwelt-hive"
description = "Providing the backbone of Umwelts internal services"
}

resource "aws_elastic_beanstalk_environment" "hive-dev" {
name = "umw-hive-dev"
application = "${aws_elastic_beanstalk_application.hive.name}"
description = "Development environment"
solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.6 running Docker 1.11.2"
wait_for_ready_timeout = "10m"
}
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/plugin"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() terraform.ResourceProvider {
return Provider()
},
})
}
82 changes: 82 additions & 0 deletions provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"github.com/hashicorp/terraform/helper/schema"
)

func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["user"],
},

"password": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["password"],
},

"url": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["url"],
},

"insecure": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: descriptions["insecure"],
},

"skip_credentials_validation": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: descriptions["skip_credentials_validation"],
},
},
ResourcesMap: map[string]*schema.Resource{
"teamcity_project": resourceProject(),
"teamcity_build_configuration": resourceBuildConfiguration(),
"teamcity_build_template": resourceBuildTemplate(),
},
ConfigureFunc: providerConfigure,
}
}

var descriptions map[string]string

func init() {
descriptions = map[string]string{
"user": "The username used for API operations. This must be \n" +
"an admin user created on the TeamCity Server.",

"password": "Password of the TeamCity user. The password for the user \n" +
"specified in the user option.",

"url": "URL of the TeamCity server to connect to. If not set, the default profile\n" +
"created with `aws configure` will be used.",

"insecure": "Explicitly allow the provider to perform \"insecure\" SSL requests. If omitted," +
"default value is `false`",
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
User: d.Get("user").(string),
Password: d.Get("password").(string),
URL: d.Get("url").(string),
Insecure: d.Get("insecure").(bool),
SkipCredsValidation: d.Get("skip_credentials_validation").(bool),
}

return config.Client()
}
42 changes: 42 additions & 0 deletions provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
//"log"
"os"
"testing"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)

var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider

func init() {
testAccProvider = Provider()
testAccProviders = map[string]terraform.ResourceProvider{
"teamcity": testAccProvider,
}
}

func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}

func testAccPreCheck(t *testing.T) {
if v := os.Getenv("TEAMCITY_URL"); v == "" {
t.Fatal("TEAMCITY_URL must be set for acceptance tests")
}
if v := os.Getenv("TEAMCITY_USER"); v == "" {
t.Fatal("TEAMCITY_USER must be set for acceptance tests")
}
if v := os.Getenv("TEAMCITY_PASSWORD"); v == "" {
t.Fatal("TEAMCITY_PASSWORD must be set for acceptance tests")
}
}
Loading

0 comments on commit 5ddd7c8

Please sign in to comment.