-
Notifications
You must be signed in to change notification settings - Fork 4
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
0 parents
commit b1feff2
Showing
1,550 changed files
with
505,649 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,13 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# terraform lock file | ||
.terraform.lock.hcl | ||
|
||
# logs and plan | ||
*.plan | ||
*.log |
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 @@ | ||
TEST?=$$(go list ./citrixadm/... | grep -v 'vendor') | ||
HOSTNAME=registry.terraform.io | ||
NAMESPACE=citrix | ||
NAME=citrixadm | ||
BINARY=terraform-provider-${NAME} | ||
VERSION=0.1.0 | ||
OS_ARCH=darwin_amd64 | ||
|
||
default: install | ||
|
||
docgen: | ||
tfplugindocs | ||
|
||
build: fmt | ||
go build -o ${BINARY} | ||
|
||
debug-build: fmt | ||
go build -gcflags="all=-N -l" -o ${BINARY} | ||
cp -f ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} | ||
|
||
release: | ||
goreleaser release --rm-dist --snapshot --skip-publish --skip-sign | ||
|
||
fmt: | ||
go fmt ./... | ||
|
||
tffmt: | ||
terraform fmt -list=true -recursive examples | ||
|
||
|
||
install: build | ||
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} | ||
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} | ||
|
||
testacc: | ||
# Usage: make testacc VPX_IP=10.0.1.76 VPX_USER=nsroot VPX_PASSWORD=verysecretpassword AGENT_IP=10.0.1.91 | ||
- rm -i citrixadm/citrixadm.acctest.log | ||
TF_ACC=1 TF_ACC_LOG_PATH=./citrixadm.acctest.log TF_LOG=TRACE VPX_IP=$(VPX_IP) VPX_USER=$(VPX_USER) VPX_PASSWORD=$(VPX_PASSWORD) AGENT_IP=$(AGENT_IP) go test terraform-provider-citrixadm/citrixadm -v | ||
|
||
start-debug: debug-build | ||
~/go/bin/dlv exec --accept-multiclient --continue --headless ./${BINARY} -- -debug |
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 @@ | ||
package citrixadm | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"terraform-provider-citrixadm/service" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceManagedDevice() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Configuration for MPS Agent information data source.", | ||
ReadContext: dataSourceManagedDeviceRead, | ||
Schema: map[string]*schema.Schema{ | ||
"ip_address": { | ||
Description: "IP Address for this managed device", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceManagedDeviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("In dataSourceManagedDeviceRead") | ||
var diags diag.Diagnostics | ||
c := m.(*service.NitroClient) | ||
|
||
resourceID, err := getManagedDeviceID(c, d.Get("ip_address").(string)) | ||
|
||
if err != nil { | ||
return diag.Errorf("unable to get Managed Device ID: %s", err.Error()) | ||
} | ||
d.SetId(resourceID) | ||
d.Set("ip_address", d.Get("ip_address").(string)) | ||
|
||
return diags | ||
} |
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,63 @@ | ||
package citrixadm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"terraform-provider-citrixadm/service" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceMpsAgent() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Configuration for MPS Agent information data source.", | ||
ReadContext: dataSourceMpsAgentRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Description: "Agent IP Address", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"datacenter_id": { | ||
Description: "Datacenter Id is system generated key for data center", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMpsAgentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("In dataSourceMpsAgentRead") | ||
var diags diag.Diagnostics | ||
c := m.(*service.NitroClient) | ||
|
||
endpoint := "mps_agent" | ||
|
||
agentIP := d.Get("name").(string) | ||
|
||
returnData, err := c.GetAllResource(endpoint) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
// Find the correct resource with the given name and store agent_id and datacenter_id from the object | ||
for _, v := range returnData[endpoint].([]interface{}) { | ||
agent := v.(map[string]interface{}) | ||
if agent["name"].(string) == agentIP { | ||
d.SetId(agent["id"].(string)) | ||
d.Set("name", agent["name"].(string)) | ||
d.Set("datacenter_id", agent["datacenter_id"].(string)) | ||
break | ||
} | ||
} | ||
if d.Id() == "" { | ||
return diag.FromErr(fmt.Errorf("Mps Agent with name %s not found", agentIP)) | ||
} | ||
return diags | ||
} |
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,88 @@ | ||
package citrixadm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"terraform-provider-citrixadm/service" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// Provider - | ||
func Provider() *schema.Provider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"host": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CITRIXADM_HOST", nil), | ||
Description: "Citrix Adm host. Can be specified with `CITRIXADM_HOST` environment variable. This has to start with https://", | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
// if the value does not start with http, throw an error | ||
if !strings.HasPrefix(v.(string), "https://") { | ||
errors = append(errors, fmt.Errorf("host must start with https://")) | ||
} | ||
return | ||
}, | ||
}, | ||
"client_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CITRIXADM_CLIENT_ID", nil), | ||
Description: "Citrix Adm client id. Can be specified with `CITRIXADM_CLIENT_ID` environment variable.", | ||
}, | ||
"client_secret": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Sensitive: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CITRIXADM_CLIENT_SECRET", nil), | ||
Description: "Citrix Adm client secret. Can be specified with `CITRIXADM_CLIENT_SECRET` environment variable.", | ||
}, | ||
"host_location": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CITRIXADM_HOST_LOCATION", ""), | ||
Description: "Citrix Adm host location, e.g. `us`, `eu`. Can be specified with `CITRIXADM_HOST_LOCATION` environment variable.", | ||
}, | ||
"customer_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CITRIXADM_CUSTOMER_ID", ""), | ||
Description: "Citrix Adm customer/tenant id. Can be specified with `CITRIXADM_CUSTOMER_ID` environment variable.", | ||
}, | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"citrixadm_managed_device": resourceManagedDevice(), | ||
"citrixadm_ns_device_profile": resourceNsDeviceProfile(), | ||
"citrixadm_managed_device_allocate_license": resourceManagedDeviceAllocateLicense(), | ||
"citrixadm_stylebook_configpack": resourceStylebookConfigpack(), | ||
"citrixadm_stylebook": resourceStylebook(), | ||
}, | ||
DataSourcesMap: map[string]*schema.Resource{ | ||
"citrixadm_mps_agent": dataSourceMpsAgent(), | ||
"citrixadm_managed_device": dataSourceManagedDevice(), | ||
}, | ||
ConfigureContextFunc: providerConfigure, | ||
} | ||
} | ||
|
||
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { | ||
tflog.Trace(ctx, "In providerConfigure") | ||
var diags diag.Diagnostics | ||
params := service.NitroParams{ | ||
Host: d.Get("host").(string), | ||
HostLocation: d.Get("host_location").(string), | ||
ID: d.Get("client_id").(string), | ||
Secret: d.Get("client_secret").(string), | ||
CustomerID: d.Get("customer_id").(string), | ||
} | ||
c, err := service.NewNitroClientFromParams(params) | ||
if err != nil { | ||
return nil, diag.FromErr(err) | ||
} | ||
|
||
return c, diags | ||
} |
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,52 @@ | ||
package citrixadm | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// providerFactories are used to instantiate a provider during acceptance testing. | ||
// The factory function will be invoked for every Terraform CLI command executed | ||
// to create a provider server to which the CLI can reattach. | ||
// var providerFactories = map[string]func() (*schema.Provider, error){ | ||
// "citrixadm": func() (*schema.Provider, error) { | ||
// return New("dev")(), nil | ||
// }, | ||
// } | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := Provider().InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func TestProvider_impl(t *testing.T) { | ||
var _ *schema.Provider = Provider() | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
requiredEnvVariables := []string{ | ||
"CITRIXADM_HOST", | ||
"CITRIXADM_CLIENT_ID", | ||
"CITRIXADM_CLIENT_SECRET", | ||
"CITRIXADM_HOST_LOCATION", | ||
"CITRIXADM_CUSTOMER_ID", | ||
} | ||
for _, envVar := range requiredEnvVariables { | ||
if v := os.Getenv(envVar); v == "" { | ||
t.Fatalf("%s must be set for acceptance tests", envVar) | ||
} | ||
} | ||
} | ||
|
||
var testAccProviders map[string]*schema.Provider | ||
var testAccProvider *schema.Provider | ||
|
||
func init() { | ||
testAccProvider = Provider() | ||
testAccProviders = map[string]*schema.Provider{ | ||
"citrixadm": testAccProvider, | ||
} | ||
} |
Oops, something went wrong.