-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,390 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform.tfstate* | ||
terraform-provider-teamcity | ||
|
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,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 | ||
} |
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,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" | ||
} |
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 @@ | ||
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() | ||
}, | ||
}) | ||
} |
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,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() | ||
} |
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,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") | ||
} | ||
} |
Oops, something went wrong.