<commit_before>// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

package main

import (
	"errors"
	"fmt"
	"net/http"

	"github.com/MustWin/baremetal-sdk-go"
	"github.com/hashicorp/terraform/helper/schema"
	"github.com/hashicorp/terraform/terraform"
)

var descriptions map[string]string

func init() {
	descriptions = map[string]string{
		"tenancy_ocid": "(Required) The tenancy OCID for a user. The tenancy OCID can be found at the bottom of user settings in the Bare Metal console.",
		"user_ocid":    "(Required) The user OCID. This can be found in user settings in the Bare Metal console.",
		"fingerprint":  "(Required) The fingerprint for the user's RSA key. This can be found in user settings in the Bare Metal console.",
		"private_key": "(Optional) A PEM formatted RSA private key for the user.\n" +
			"A private_key or a private_key_path must be provided.",
		"private_key_path": "(Optional) The path to the user's PEM formatted private key.\n" +
			"A private_key or a private_key_path must be provided.",
		"private_key_password": "(Optional) The password used to secure the private key.",
	}
}

// Provider is the adapter for terraform, that gives access to all the resources
func Provider(configfn schema.ConfigureFunc) terraform.ResourceProvider {
	return &schema.Provider{
		DataSourcesMap: dataSourcesMap(),
		Schema:         schemaMap(),
		ResourcesMap:   resourcesMap(),
		ConfigureFunc:  configfn,
	}
}

func schemaMap() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"tenancy_ocid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["tenancy_ocid"],
		},
		"user_ocid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["user_ocid"],
		},
		"fingerprint": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["fingerprint"],
		},
		// Mostly used for testing. Don't put keys in your .tf files
		"private_key": {
			Type:        schema.TypeString,
			Optional:    true,
			Default:     "",
			Sensitive:   true,
			Description: descriptions["private_key"],
		},
		"private_key_path": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: descriptions["private_key_path"],
		},
		"private_key_password": {
			Type:        schema.TypeString,
			Optional:    true,
			Sensitive:   true,
			Default:     "",
			Description: descriptions["private_key_password"],
		},
	}
}

func dataSourcesMap() map[string]*schema.Resource {
	return map[string]*schema.Resource{
		"baremetal_core_console_history_data":       ConsoleHistoryDataDatasource(),
		"baremetal_core_cpes":                       CpeDatasource(),
		"baremetal_core_dhcp_options":               DHCPOptionsDatasource(),
		"baremetal_core_drg_attachments":            DrgAttachmentDatasource(),
		"baremetal_core_drgs":                       DrgDatasource(),
		"baremetal_core_images":                     ImageDatasource(),
		"baremetal_core_instance_credentials":       InstanceCredentialsDatasource(),
		"baremetal_core_instances":                  InstanceDatasource(),
		"baremetal_core_internet_gateways":          InternetGatewayDatasource(),
		"baremetal_core_ipsec_config":               IPSecConnectionConfigDatasource(),
		"baremetal_core_ipsec_connections":          IPSecConnectionsDatasource(),
		"baremetal_core_ipsec_status":               IPSecConnectionStatusDatasource(),
		"baremetal_core_route_tables":               RouteTableDatasource(),
		"baremetal_core_security_lists":             SecurityListDatasource(),
		"baremetal_core_shape":                      InstanceShapeDatasource(),
		"baremetal_core_subnets":                    SubnetDatasource(),
		"baremetal_core_virtual_networks":           VirtualNetworkDatasource(),
		"baremetal_core_vnic":                       VnicDatasource(),
		"baremetal_core_vnic_attachments":           DatasourceCoreVnicAttachments(),
		"baremetal_core_volume_attachments":         VolumeAttachmentDatasource(),
		"baremetal_core_volume_backups":             VolumeBackupDatasource(),
		"baremetal_core_volumes":                    VolumeDatasource(),
		"baremetal_database_database":               DatabaseDatasource(),
		"baremetal_database_databases":              DatabasesDatasource(),
		"baremetal_database_db_home":                DBHomeDatasource(),<commit_msg>Add explicit environment variable interpolation for provider schema values. All of these are preceeded with 'OBMCS', which may break environment oriented setups.<commit_after>// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

package main

import (
	"errors"
	"fmt"
	"net/http"

	"github.com/MustWin/baremetal-sdk-go"
	"github.com/hashicorp/terraform/helper/schema"
	"github.com/hashicorp/terraform/terraform"
)

var descriptions map[string]string

func init() {
	descriptions = map[string]string{
		"tenancy_ocid": "(Required) The tenancy OCID for a user. The tenancy OCID can be found at the bottom of user settings in the Bare Metal console.",
		"user_ocid":    "(Required) The user OCID. This can be found in user settings in the Bare Metal console.",
		"fingerprint":  "(Required) The fingerprint for the user's RSA key. This can be found in user settings in the Bare Metal console.",
		"private_key": "(Optional) A PEM formatted RSA private key for the user.\n" +
			"A private_key or a private_key_path must be provided.",
		"private_key_path": "(Optional) The path to the user's PEM formatted private key.\n" +
			"A private_key or a private_key_path must be provided.",
		"private_key_password": "(Optional) The password used to secure the private key.",
	}
}

// Provider is the adapter for terraform, that gives access to all the resources
func Provider(configfn schema.ConfigureFunc) terraform.ResourceProvider {
	return &schema.Provider{
		DataSourcesMap: dataSourcesMap(),
		Schema:         schemaMap(),
		ResourcesMap:   resourcesMap(),
		ConfigureFunc:  configfn,
	}
}

func schemaMap() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"tenancy_ocid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["tenancy_ocid"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_TENANCY_OCID", nil),
		},
		"user_ocid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["user_ocid"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_USER_OCID", nil),
		},
		"fingerprint": {
			Type:        schema.TypeString,
			Required:    true,
			Description: descriptions["fingerprint"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_FINGERPRINT", nil),
		},
		// Mostly used for testing. Don't put keys in your .tf files
		"private_key": {
			Type:        schema.TypeString,
			Optional:    true,
			Default:     "",
			Sensitive:   true,
			Description: descriptions["private_key"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_PRIVATE_KEY", nil),
		},
		"private_key_path": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: descriptions["private_key_path"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_PRIVATE_KEY_PATH", nil),
		},
		"private_key_password": {
			Type:        schema.TypeString,
			Optional:    true,
			Sensitive:   true,
			Default:     "",
			Description: descriptions["private_key_password"],
			DefaultFunc: schema.EnvDefaultFunc("OBMCS_PRIVATE_KEY_PASSWORD", nil),
		},
	}
}

func dataSourcesMap() map[string]*schema.Resource {
	return map[string]*schema.Resource{
		"baremetal_core_console_history_data":       ConsoleHistoryDataDatasource(),
		"baremetal_core_cpes":                       CpeDatasource(),
		"baremetal_core_dhcp_options":               DHCPOptionsDatasource(),
		"baremetal_core_drg_attachments":            DrgAttachmentDatasource(),
		"baremetal_core_drgs":                       DrgDatasource(),
		"baremetal_core_images":                     ImageDatasource(),
		"baremetal_core_instance_credentials":       InstanceCredentialsDatasource(),
		"baremetal_core_instances":                  InstanceDatasource(),
		"baremetal_core_internet_gateways":          InternetGatewayDatasource(),
		"baremetal_core_ipsec_config":               IPSecConnectionConfigDatasource(),
		"baremetal_core_ipsec_connections":          IPSecConnectionsDatasource(),
		"baremetal_core_ipsec_status":               IPSecConnectionStatusDatasource(),
		"baremetal_core_route_tables":               RouteTableDatasource(),
		"baremetal_core_security_lists":             SecurityListDatasource(),
		"baremetal_core_shape":                      InstanceShapeDatasource(),
		"baremetal_core_subnets":                    SubnetDatasource(),
		"baremetal_core_virtual_networks":           VirtualNetworkDatasource(),
		"baremetal_core_vnic":                       VnicDatasource(),
		"baremetal_core_vnic_attachments":           DatasourceCoreVnicAttachments(),
		"baremetal_core_volume_attachments":         VolumeAttachmentDatasource(),
		"baremetal_core_volume_backups":             VolumeBackupDatasource(),
		"baremetal_core_volumes":                    VolumeDatasource(),
		"baremetal_database_database":               DatabaseDatasource(),
		"baremetal_database_databases":              DatabasesDatasource(),
		"baremetal_database_db_home":                DBHomeDatasource(),
{'fraction_non_alphanumeric': 0.10067690985279897, 'fraction_numerical': 0.0008595680670463093, 'mean_word_length': 3.527237354085603, 'pattern_counts': {'":': 74, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7336491', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2722, 'n_words': 606}