Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Azure single peering #2

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ HOSTNAME=registry.terraform.io
NAMESPACE=megaport
NAME=megaport
BINARY=terraform-provider-${NAME}
VERSION=0.2.9
VERSION=0.2.10-stateless-4
OS_ARCH=$$(go version | cut -d" " -f4 | sed 's/\//_/g')
ZIP_FILE=terraform-provider-${NAME}_${VERSION}_${OS_ARCH}.zip

Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

provider_directory="$(pwd)"
GO111MODULE=on GOSUMDB=off go get -d github.com/megaport/megaportgo
GOSUMDB=off go mod download
rm -f bin/*
version="$(git describe --tags)"
version="v0.2.10-stateless-4"
provider_filename="$(pwd)/bin/terraform-provider-megaport_$version"
provider_filename_no_version="$(pwd)/bin/terraform-provider-megaport"
go build -o $provider_filename
Expand All @@ -26,10 +26,10 @@ cd ~
arch=$(go version | cut -d" " -f4 | sed 's/\//_/g')
plugin_directory="$(pwd)/.terraform.d/plugins/${arch}/"
mkdir -p $plugin_directory
ln -s $provider_filename_no_version $plugin_directory
ln -s --force $provider_filename_no_version $plugin_directory
echo "Symbolic link created from build directory to terraform.d. < 0.13"
plugin_directory="$(pwd)/.terraform.d/plugins/megaport.com/megaport/megaport/${version:1}/${arch}/"
mkdir -p $plugin_directory
ln -s $provider_filename_no_version $plugin_directory
ln -s --force $provider_filename_no_version $plugin_directory
echo "Symbolic link created from build directory to terraform.d. >= 0.13"
cd $provider_directory
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_aws_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
)

Expand Down
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_azure_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
)

Expand Down
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_gcp_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
)

Expand Down
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/megaportgo/types"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
Expand Down
81 changes: 81 additions & 0 deletions data_megaport/data_megaport_locations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 Megaport Pty Ltd
//
// Licensed under the Mozilla Public License, Version 2.0 (the
// "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package data_megaport

import (
"context"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)

func MegaportLocations() *schema.Resource {
return &schema.Resource{
ReadContext: dataMegaportLocationsRead,
Schema: schema_megaport.DataLocationsSchema(),
}
}

func dataMegaportLocationsRead(c context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
errors := make([]diag.Diagnostic, 0)
location := m.(*terraform_utility.MegaportClient).Location
locationsResponse, err := location.GetAllLocations()
if err != nil {
errors = append(errors, diag.Diagnostic{
Severity: diag.Error,
Summary: "Failed to get megaport locations list",
Detail: err.Error(),
AttributePath: make([]cty.PathStep, 0),
})
return errors
}

locations := make([]map[string]interface{}, len(locationsResponse))

for i, loc := range locationsResponse {
location := make(map[string]interface{})
location["address"] = loc.Address
location["country"] = loc.Country
location["has_mcr"] = loc.VRouterAvailable
location["id"] = loc.ID
location["latitude"] = loc.Latitude
location["live_date"] = loc.LiveDate
location["longitude"] = loc.Longitude
location["market"] = loc.Market
location["metro"] = loc.Metro
location["name"] = loc.Name
location["site_code"] = loc.SiteCode
location["status"] = loc.Status
locations[i] = location
}

id, err := uuid.GenerateUUID()

if err != nil {
errors = append(errors, diag.Diagnostic{
Severity: diag.Error,
Summary: err.Error(),
Detail: "Failed to generate UUID as Id",
AttributePath: make([]cty.PathStep, 0),
})
return errors
}
d.Set("locations", &locations)
d.SetId(id)
return errors
}
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)
Expand Down
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_partner_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package data_megaport
import (
"errors"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)
Expand Down
4 changes: 2 additions & 2 deletions data_megaport/data_megaport_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)

func MegaportPort() *schema.Resource {
return &schema.Resource{
Read: dataMegaportPortRead,
Schema: schema_megaport.DataPortSchema(),
Schema: schema_megaport.ResourcePortSchema(),
}
}

Expand Down
78 changes: 78 additions & 0 deletions data_megaport/data_megaport_ports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2020 Megaport Pty Ltd
//
// Licensed under the Mozilla Public License, Version 2.0 (the
// "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package data_megaport

import (
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/megaportgo/types"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)

func MegaportPorts() *schema.Resource {
return &schema.Resource{
Read: dataMegaportPortsRead,
Schema: schema_megaport.DataPortsSchema(),
}
}

func dataMegaportPortsRead(d *schema.ResourceData, m interface{}) error {
port := m.(*terraform_utility.MegaportClient).Port

id, err := uuid.GenerateUUID()

if err != nil {
return err
}

ports, retrievalErr := port.GetPorts()

if retrievalErr != nil {
return retrievalErr
}

converted := make([]map[string]interface{}, len(ports))

for i, port := range ports {
converted[i] = tfizePort(port)
}

d.SetId(id)

return d.Set("ports", &converted)
}

func tfizePort(port types.Port) map[string]interface{} {
tf := make(map[string]interface{})
tf["admin_locked"] = port.AdminLocked
tf["company_name"] = port.CompanyName
tf["create_date"] = port.CreateDate
tf["created_by"] = port.CreatedBy
tf["lag_id"] = port.LAGID
tf["lag_primary"] = port.LAGPrimary
tf["live_date"] = port.LiveDate
tf["location_id"] = port.LocationID
tf["locked"] = port.Locked
tf["market_code"] = port.Market
tf["marketplace_visibility"] = port.MarketplaceVisibility
tf["port_name"] = port.Name
tf["port_speed"] = port.PortSpeed
tf["provisioning_status"] = port.ProvisioningStatus
tf["term"] = port.ContractTermMonths
tf["type"] = port.Type
tf["uid"] = port.UID
return tf
}
2 changes: 1 addition & 1 deletion data_megaport/data_megaport_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package data_megaport

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/schema_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
)
Expand Down
52 changes: 49 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,57 @@ module github.com/megaport/terraform-provider-megaport

// For local development
//replace github.com/megaport/megaportgo => <megaportgo local directory>
// azure-single-peering
replace github.com/megaport/megaportgo => github.com/bestateless/megaportgo v0.1.11-stateless.0.20230522231232-6a2eaee5047e

go 1.13
go 1.20

require (
github.com/aws/aws-sdk-go v1.25.3
github.com/hashicorp/terraform-plugin-sdk v1.9.1
github.com/aws/aws-sdk-go v1.44.267
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/megaport/megaportgo v0.1.15-beta
)

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.16.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.15.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.8.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.0 // indirect
github.com/hashicorp/terraform-svchost v0.1.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xlzd/gotp v0.1.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
package main

import (
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/megaport/terraform-provider-megaport/provider"
)
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() terraform.ResourceProvider {
return Provider()
ProviderFunc: func() *schema.Provider {
return provider.Provider()
},
})
}
8 changes: 6 additions & 2 deletions provider.go → provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package provider

import (
"errors"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/megaport/terraform-provider-megaport/data_megaport"
"github.com/megaport/terraform-provider-megaport/resource_megaport"
"github.com/megaport/terraform-provider-megaport/terraform_utility"
Expand Down Expand Up @@ -47,11 +47,13 @@ func Provider() *schema.Provider {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("MEGAPORT_PASSWORD", nil),
Sensitive: true,
},
"mfa_otp_key": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("MEGAPORT_MFA_OTP_KEY", nil),
Sensitive: true,
},
"delete_ports": {
Type: schema.TypeBool,
Expand All @@ -70,7 +72,9 @@ func Provider() *schema.Provider {
ConfigureFunc: providerConfigure,
DataSourcesMap: map[string]*schema.Resource{
"megaport_port": data_megaport.MegaportPort(),
"megaport_ports": data_megaport.MegaportPorts(),
"megaport_location": data_megaport.MegaportLocation(),
"megaport_locations": data_megaport.MegaportLocations(),
"megaport_vxc": data_megaport.MegaportVXC(),
"megaport_partner_port": data_megaport.MegaportPartnerPort(),
"megaport_aws_connection": data_megaport.MegaportAWSConnection(),
Expand Down
Loading