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
17 changed files
with
1,338 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,2 @@ | ||
release | ||
bin/terraform-provider-akamai/build |
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,22 @@ | ||
# Contribution Guidelines | ||
|
||
We love to see contributions to the project and have tried to make it easy to do so. If you would like to contribute code to this project you can do so through GitHub by forking the repository and sending a pull request. | ||
|
||
Before Comcast merges your code into the project you must sign the [Comcast Contributor License Agreement (CLA)](https://gist.github.com/ComcastOSS/a7b8933dd8e368535378cda25c92d19a). | ||
|
||
If you haven't previously signed a Comcast CLA, you'll automatically be asked to when you open a pull request. Alternatively, we can e-mail you a PDF that you can sign and scan back to us. Please send us an e-mail or create a new GitHub issue to request a PDF version of the CLA. | ||
|
||
For more details about contributing to GitHub projects see | ||
http://gun.io/blog/how-to-github-fork-branch-and-pull-request/ | ||
|
||
## Testing | ||
|
||
## Pull Requests | ||
|
||
* should be from a forked project with an appropriate branch name | ||
* should be narrowly focused with no more than 3 or 4 logical commits | ||
* when possible, address no more than one issue | ||
* should be reviewable in the GitHub code review tool | ||
* should be linked to any issues to which it relates (i.e. issue number after (#) in commit messages or pull request message) | ||
|
||
Expect a thorough review process for any pull requests that add functionality or change the behavior of the application. We encourage you to sketch your approach in writing on a relevant issue (or creating such an issue if needed) before starting to code, in order to save time and facilitate communication. |
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,54 @@ | ||
NAME=terraform-provider-akamai | ||
VERSION=0.2.1 | ||
|
||
all: updatedeps test install | ||
|
||
updatedeps: | ||
@go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \ | ||
go get -u golang.org/x/tools/cmd/cover; \ | ||
fi | ||
go get -u github.com/mitchellh/gox | ||
go get -u github.com/aktau/github-release | ||
go get | ||
|
||
test: | ||
go test $(TEST) -cover | ||
TF_LOG=DEBUG TF_ACC=1 go test -v | ||
|
||
cover: | ||
go test $(TEST) -coverprofile=coverage.out | ||
go tool cover -html=coverage.out | ||
rm coverage.out | ||
|
||
install: | ||
cd bin/${NAME} \ | ||
&& go install | ||
|
||
build: | ||
cd bin/${NAME} \ | ||
&& rm -rf build \ | ||
&& gox -ldflags "-X main.version=${VERSION}" \ | ||
-os "linux darwin windows" \ | ||
-arch "386 amd64" \ | ||
-output "build/{{.OS}}_{{.Arch}}/${NAME}" | ||
|
||
package: | ||
rm -rf release | ||
mkdir release | ||
for f in bin/$(NAME)/build/*; do \ | ||
g=`basename $$f`; \ | ||
tar -zcf release/$(NAME)-$${g}-$(VERSION).tgz -C bin/$(NAME)/build/$${g} .; \ | ||
done | ||
|
||
release: package | ||
github-release release \ | ||
-u Comcast -r ${NAME} \ | ||
-c $(shell git rev-parse --abbrev-ref HEAD) \ | ||
--tag ${VERSION} \ | ||
--name "Release: ${VERSION}" | ||
ls release/*.tgz | xargs -I FILE github-release upload \ | ||
-u Comcast \ | ||
-r ${NAME} \ | ||
--tag ${VERSION} \ | ||
--name FILE \ | ||
--file FILE |
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,5 @@ | ||
terraform-provider-akamai | ||
|
||
Copyright 2017 Comcast Cable Communications Management, LLC | ||
|
||
This product includes software developed at Comcast (http://www.comcast.com/) |
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,73 @@ | ||
# terraform-provider-akamai | ||
|
||
An Akamai provider for HashiCorp [Terraform](http://terraform.io). | ||
|
||
## Installation | ||
|
||
1. Download the desired [release](https://github.com/Comcast/terraform-provider-akamai/releases) version for your operating system | ||
2. Untar the download contents | ||
3. Install the `terraform-provider-akamai` anywhere on your system | ||
4. Add `terraform-provider-akamai` to your `~/.terraformrc` file: | ||
|
||
``` | ||
providers { | ||
"akamai" = "path/to/your/terraform-provider-akamai" | ||
} | ||
``` | ||
|
||
### Install from source | ||
|
||
If you'd prefer to install from source: | ||
|
||
1. Add `terraform-provider-akamai` to your `~/.terraformrc` file: | ||
|
||
``` | ||
providers { | ||
"akamai" = "$GOPATH/bin/terraform-provider-akamai" | ||
} | ||
``` | ||
|
||
2. Install `terraform-provider-akamai`: | ||
|
||
``` | ||
git clone git@github.com:Comcast/terraform-provider-akamai.git | ||
cd terraform-provider-akamai | ||
make | ||
``` | ||
|
||
## Environment | ||
|
||
Note that `terraform-provider-akamai` assumes the following Akamai credentials stored as environment variables: | ||
|
||
``` | ||
export AKAMAI_EDGEGRID_HOST=https://some-host.luna.akamaiapis.net | ||
export AKAMAI_EDGEGRID_ACCESS_TOKEN=some-access-token | ||
export AKAMAI_EDGEGRID_CLIENT_TOKEN=some-client-token | ||
export AKAMAI_EDGEGRID_CLIENT_SECRET=some-client-secret | ||
``` | ||
|
||
## Usage | ||
|
||
See `example.tf` as a usage reference. | ||
|
||
### WARNING! | ||
|
||
When using `terraform-provider-akamai` against an existing Akamai GTM domain with existing Akamai GTM properties, | ||
Terraform will destroy all existing Akamai GTM properties associated with the `resource "akamai_gtm_domain"` | ||
cited in your `.tf file`. If undesired, this destructive action can be avoided by omitting usage of the | ||
`resource "akamai_gtm_domain"` in your `.tf` file. | ||
|
||
### Acceptance Tests | ||
|
||
``` | ||
TF_ACC=1 go test -v | ||
``` | ||
|
||
## Releasing new versons | ||
|
||
To publish a new `terraform-provider-akamai` [GitHub release](https://github.com/Comcast/terraform-provider-akamai/releases) from your git repository's `HEAD`... | ||
|
||
1. establish a `GITHUB_API_URL` env variable: `export GITHUB_API_URL=https://github.com/api/v3` | ||
1. establish a `GITHUB_ACCESS_TOKEN` env variable: `export GITHUB_ACCESS_TOKEN=YOUR_ACCESS_TOKEN` | ||
1. edit `Makefile`'s `VERSION` variable to the appropriate semantic version | ||
1. execute `make release` |
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 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/Comcast/terraform-provider-akamai" | ||
"github.com/hashicorp/terraform/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeOpts{ | ||
ProviderFunc: akamai.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,35 @@ | ||
package akamai | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/Comcast/go-edgegrid/edgegrid" | ||
) | ||
|
||
// Config is the configuration required to instantiate | ||
// Akamai API clients | ||
type Config struct { | ||
AccessToken string | ||
ClientToken string | ||
ClientSecret string | ||
APIHost string | ||
} | ||
|
||
// Clients contains Akamai GTM and PAPI clients for | ||
// accessing the Akamai API. | ||
type Clients struct { | ||
GTM *edgegrid.GTMClient | ||
PAPI *edgegrid.PAPIClient | ||
} | ||
|
||
// Client returns a new AkamaiClients for accessing Akamai. | ||
func (c *Config) Client() (*Clients, error) { | ||
clients := &Clients{ | ||
edgegrid.GTMClientWithCreds(c.AccessToken, c.ClientToken, c.ClientSecret, c.APIHost), | ||
edgegrid.PAPIClientWithCreds(c.AccessToken, c.ClientToken, c.ClientSecret, c.APIHost), | ||
} | ||
|
||
log.Printf("[INFO] Akamai GTM and PAPI API Clients configured for use") | ||
|
||
return clients, 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,83 @@ | ||
resource "akamai_gtm_domain" "property_test_domain" { | ||
name = "test.akadns.net" | ||
type = "basic" | ||
} | ||
|
||
resource "akamai_gtm_data_center" "property_test_dc1" { | ||
name = "property_test_dc1" | ||
domain = "${akamai_gtm_domain.property_test_domain.name}" | ||
country = "GB" | ||
continent = "EU" | ||
city = "Downpatrick" | ||
longitude = -5.582 | ||
latitude = 54.367 | ||
depends_on = [ | ||
"akamai_gtm_domain.property_test_domain" | ||
] | ||
} | ||
|
||
resource "akamai_gtm_data_center" "property_test_dc2" { | ||
name = "property_test_dc2" | ||
domain = "${akamai_gtm_domain.property_test_domain.name}" | ||
country = "IS" | ||
continent = "EU" | ||
city = "Snæfellsjökull" | ||
longitude = -23.776 | ||
latitude = 64.808 | ||
depends_on = [ | ||
"akamai_gtm_data_center.property_test_dc1" | ||
] | ||
} | ||
|
||
resource "akamai_gtm_property" "test_property" { | ||
domain = "${akamai_gtm_domain.property_test_domain.name}" | ||
type = "weighted-round-robin" | ||
name = "test_property" | ||
balance_by_download_score = false | ||
dynamic_ttl = 300 | ||
failover_delay = 0 | ||
failback_delay = 0 | ||
handout_mode = "normal" | ||
health_threshold = 0 | ||
health_max = 0 | ||
health_multiplier = 0 | ||
load_imbalance_percentage = 10 | ||
ipv6 = false | ||
score_aggregation_type = "mean" | ||
static_ttl = 600 | ||
stickiness_bonus_percentage = 50 | ||
stickiness_bonus_constant = 0 | ||
use_computed_targets = false | ||
liveness_test { | ||
name = "health check" | ||
test_object = "/status" | ||
test_object_protocol = "HTTP" | ||
test_interval = 60 | ||
disable_nonstandard_port_warning = false | ||
http_error_4xx = true | ||
http_error_3xx = true | ||
http_error_5xx = true | ||
test_object_port = 80 | ||
test_timeout = 25 | ||
} | ||
traffic_target { | ||
enabled = true | ||
data_center_id = "${akamai_gtm_data_center.property_test_dc1.id}" | ||
weight = 50.0 | ||
name = "${akamai_gtm_data_center.property_test_dc1.name}" | ||
servers = [ | ||
"1.2.3.4", | ||
"1.2.3.5" | ||
] | ||
} | ||
traffic_target { | ||
enabled = true | ||
data_center_id = "${akamai_gtm_data_center.property_test_dc2.id}" | ||
weight = 50.0 | ||
name = "${akamai_gtm_data_center.property_test_dc2.name}" | ||
servers = [ | ||
"1.2.3.6", | ||
"1.2.3.7" | ||
] | ||
} | ||
} |
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,72 @@ | ||
package akamai | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// Provider returns a schema.Provider for Akamai. | ||
func Provider() terraform.ResourceProvider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"host": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: envDefaultFunc("AKAMAI_EDGEGRID_HOST"), | ||
}, | ||
"access_token": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: envDefaultFunc("AKAMAI_EDGEGRID_ACCESS_TOKEN"), | ||
}, | ||
"client_token": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: envDefaultFunc("AKAMAI_EDGEGRID_CLIENT_TOKEN"), | ||
}, | ||
"client_secret": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: envDefaultFunc("AKAMAI_EDGEGRID_CLIENT_SECRET"), | ||
}, | ||
}, | ||
|
||
ResourcesMap: map[string]*schema.Resource{ | ||
"akamai_gtm_domain": resourceAkamaiGTMDomain(), | ||
"akamai_gtm_property": resourceAkamaiGTMProperty(), | ||
"akamai_gtm_data_center": resourceAkamaiGTMDataCenter(), | ||
}, | ||
|
||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func envDefaultFunc(k string) schema.SchemaDefaultFunc { | ||
return func() (interface{}, error) { | ||
if v := os.Getenv(k); v != "" { | ||
return v, nil | ||
} | ||
|
||
return nil, nil | ||
} | ||
} | ||
|
||
func envDefaultFuncAllowMissing(k string) schema.SchemaDefaultFunc { | ||
return func() (interface{}, error) { | ||
v := os.Getenv(k) | ||
return v, nil | ||
} | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
config := Config{ | ||
AccessToken: d.Get("access_token").(string), | ||
ClientToken: d.Get("client_token").(string), | ||
ClientSecret: d.Get("client_secret").(string), | ||
APIHost: d.Get("host").(string), | ||
} | ||
|
||
return config.Client() | ||
} |
Oops, something went wrong.