helpers

package
v0.34.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccountLevelResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		if d.Id() != "" {
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}
View Source
var DBInstanceResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("org_id", parts[0])
		d.Set("project_id", parts[1])
		d.Set("schema", parts[2])
		d.Set("identifier", parts[3])
		d.SetId(parts[3])

		return []*schema.ResourceData{d}, nil
	},
}
View Source
var DescriptionValues = []string{
	Descriptions.ConnectorRefText.String(),
	Descriptions.YamlText.String(),
}
View Source
var Descriptions = struct {
	ConnectorRefText Desc
	YamlText         Desc
}{
	ConnectorRefText: " To reference a connector at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference a connector at the account scope, prefix 'account` to the expression: account.{identifier}.",
	YamlText:         " In YAML, to reference an entity at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference an entity at the account scope, prefix 'account` to the expression: account.{identifier}. For eg, to reference a connector with identifier 'connectorId' at the organization scope in a stage mention it as connectorRef: org.connectorId.",
}
View Source
var EnvRelatedResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		partCount := len(parts)
		isAccountEntity := partCount == 2
		isOrgEntity := partCount == 3
		isProjectEntity := partCount == 4
		if isAccountEntity {
			d.Set("env_id", parts[0])
			d.Set("identifier", parts[1])
			d.SetId(parts[1])
			return []*schema.ResourceData{d}, nil
		}
		if isOrgEntity {
			d.Set("org_id", parts[0])
			d.Set("env_id", parts[1])
			d.Set("identifier", parts[2])
			d.SetId(parts[2])
			return []*schema.ResourceData{d}, nil
		}
		if isProjectEntity {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("env_id", parts[2])
			d.Set("identifier", parts[3])
			d.SetId(parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}
View Source
var GitWebhookResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("identifier", parts[0])
		if len(parts) > 1 {
			d.Set("org_id", parts[1])
		}
		if len(parts) > 2 {
			d.Set("project_id", parts[2])
		}
		d.SetId(parts[0])

		return []*schema.ResourceData{d}, nil
	},
}
View Source
var GitopsAgentProjectImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		if len(parts) == 2 {
			d.Set("agent_id", parts[0])
			d.Set("query_name", parts[1])
			d.SetId(parts[1])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 3 {
			d.Set("org_id", parts[0])
			d.Set("agent_id", parts[1])
			d.Set("query_name", parts[2])
			d.SetId(parts[2])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 4 {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("agent_id", parts[2])
			d.Set("query_name", parts[3])
			d.SetId(parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}

GitopsAgentResourceImporter defines the importer configuration for all project level gitops agent resources. The id used for the import should be in the format <agent_id>/<query_name>

View Source
var GitopsAgentResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		if len(parts) == 2 {
			d.Set("agent_id", parts[0])
			d.Set("identifier", parts[1])
			d.SetId(parts[1])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 3 {
			d.Set("org_id", parts[0])
			d.Set("agent_id", parts[1])
			d.Set("identifier", parts[2])
			d.SetId(parts[2])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 4 {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("agent_id", parts[2])
			d.Set("identifier", parts[3])
			d.SetId(parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}

GitopsAgentResourceImporter defines the importer configuration for all project level gitops agent resources. The id used for the import should be in the format <org_id>/<project_id>/<identifier>/<agentId>

View Source
var GitopsAppProjectMappingImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")

		if len(parts) == 4 {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("agent_id", parts[2])
			d.Set("argo_project_name", parts[3])

			d.SetId(parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}

GitopsAppProjectMappingImporter defines the importer configuration for app project mapping. The id used for the import should be in the format <org_id>/<project_id>/<identifier>/<argo_project_name>\ It is used always at project level.

View Source
var GitopsRepoCertResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("agent_id", parts[0])
		d.SetId(parts[1])
		return []*schema.ResourceData{d}, nil
	},
}
View Source
var MultiLevelFilterImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")

		partCount := len(parts)
		isAccountConnector := partCount == 2
		isOrgConnector := partCount == 3
		isProjectConnector := partCount == 4

		if isAccountConnector {
			d.SetId(parts[0])
			d.Set("identifier", parts[0])
			d.Set("type", parts[1])
			return []*schema.ResourceData{d}, nil
		}

		if isOrgConnector {
			d.SetId(parts[1])
			d.Set("identifier", parts[1])
			d.Set("org_id", parts[0])
			d.Set("type", parts[2])
			return []*schema.ResourceData{d}, nil
		}

		if isProjectConnector {
			d.SetId(parts[2])
			d.Set("identifier", parts[2])
			d.Set("project_id", parts[1])
			d.Set("org_id", parts[0])
			d.Set("type", parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}
View Source
var MultiLevelResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")

		partCount := len(parts)
		isAccountConnector := partCount == 1
		isOrgConnector := partCount == 2
		isProjectConnector := partCount == 3

		if isAccountConnector {
			d.SetId(parts[0])
			d.Set("identifier", parts[0])
			return []*schema.ResourceData{d}, nil
		}

		if isOrgConnector {
			d.SetId(parts[1])
			d.Set("identifier", parts[1])
			d.Set("org_id", parts[0])
			return []*schema.ResourceData{d}, nil
		}

		if isProjectConnector {
			d.SetId(parts[2])
			d.Set("identifier", parts[2])
			d.Set("project_id", parts[1])
			d.Set("org_id", parts[0])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}

MultiLevelResourceImporter defines the importer configuration for all multi level resources. The format used for the id is as follows:

  • Account Level: <identifier>
  • Org Level: <org_id>/<identifier>
  • Project Level: <org_id>/<project_id>/<identifier>
View Source
var OrgResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("org_id", parts[0])
		d.Set("identifier", parts[1])
		d.SetId(parts[1])

		return []*schema.ResourceData{d}, nil
	},
}

OrgResourceImporter defines the importer configuration for all organization level resources. The id used for the import should be in the format <org_id>/<identifier>

View Source
var PipelineResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("org_id", parts[0])
		d.Set("project_id", parts[1])
		d.Set("pipeline_id", parts[2])
		d.Set("identifier", parts[3])
		d.SetId(parts[3])

		return []*schema.ResourceData{d}, nil
	},
}

PipelineResourceImporter defines the importer configuration for all pipeline level resources.

View Source
var ProjectResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("org_id", parts[0])
		d.Set("project_id", parts[1])
		d.Set("identifier", parts[2])
		d.SetId(parts[2])

		if len(parts) == 4 {
			d.Set("git_details", []interface{}{map[string]interface{}{"branch_name": parts[3]}})
		}

		return []*schema.ResourceData{d}, nil
	},
}

ProjectResourceImporter defines the importer configuration for all project level resources. The id used for the import should be in the format <org_id>/<project_id>/<identifier> The id used for the import should be in the format <org_id>/<project_id>/<identifier>/<branch>

View Source
var RepoRuleResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		if len(parts) == 2 {
			d.Set("repo_identifier", parts[0])
			d.Set("identifier", parts[1])
			d.SetId(parts[1])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 3 {
			d.Set("org_id", parts[0])
			d.Set("repo_identifier", parts[1])
			d.Set("identifier", parts[2])
			d.SetId(parts[2])
			return []*schema.ResourceData{d}, nil
		}

		if len(parts) == 4 {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("repo_identifier", parts[2])
			d.Set("identifier", parts[3])
			d.SetId(parts[3])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}

The id used for the import should be in the format <org_id>/<project_id>/<repoIdentifier>/<identifier>

View Source
var SchemaFlagTypeValues = []string{
	SchemaFlagTypes.Required.String(),
	SchemaFlagTypes.Optional.String(),
	SchemaFlagTypes.Computed.String(),
}
View Source
var SchemaFlagTypes = struct {
	Required SchemaFlagType
	Optional SchemaFlagType
	Computed SchemaFlagType
}{
	Required: "Required",
	Optional: "Optional",
	Computed: "Computed",
}
View Source
var ServiceOverrideResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		partCount := len(parts)
		isAccountEntity := partCount == 1
		isOrgEntity := partCount == 2
		isProjectEntity := partCount == 3
		if isAccountEntity {
			d.Set("env_id", parts[0])
			return []*schema.ResourceData{d}, nil
		}
		if isOrgEntity {
			d.Set("org_id", parts[0])
			d.Set("env_id", parts[1])
			return []*schema.ResourceData{d}, nil
		}
		if isProjectEntity {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.Set("env_id", parts[2])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}
View Source
var ServiceOverrideV2ResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		partCount := len(parts)
		isAccountEntity := partCount == 1
		isOrgEntity := partCount == 2
		isProjectEntity := partCount == 3
		if isAccountEntity {
			d.SetId(parts[0])
			return []*schema.ResourceData{d}, nil
		}
		if isOrgEntity {
			d.Set("org_id", parts[0])
			d.SetId(parts[1])
			return []*schema.ResourceData{d}, nil
		}
		if isProjectEntity {
			d.Set("org_id", parts[0])
			d.Set("project_id", parts[1])
			d.SetId(parts[2])
			return []*schema.ResourceData{d}, nil
		}

		return nil, fmt.Errorf("invalid identifier: %s", d.Id())
	},
}
View Source
var TriggerResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("org_id", parts[0])
		d.Set("project_id", parts[1])
		d.Set("target_id", parts[2])
		d.Set("identifier", parts[3])
		d.SetId(parts[3])

		return []*schema.ResourceData{d}, nil
	},
}
View Source
var UserResourceImporter = &schema.ResourceImporter{
	State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
		parts := strings.Split(d.Id(), "/")
		d.Set("email", parts[0])
		if len(parts) > 1 {
			d.Set("org_id", parts[1])
		}
		if len(parts) > 2 {
			d.Set("project_id", parts[2])
		}
		return []*schema.ResourceData{d}, nil
	},
}

Functions

func BuildField added in v0.2.12

func BuildField(d *schema.ResourceData, field string) optional.String

func BuildFieldBool added in v0.29.0

func BuildFieldBool(d *schema.ResourceData, field string) optional.Bool

func BuildFieldForBoolean added in v0.17.1

func BuildFieldForBoolean(d *schema.ResourceData, field string) optional.Bool

func ExpandDelegateSelectors added in v0.2.2

func ExpandDelegateSelectors(ds []interface{}) []string

func ExpandField added in v0.2.12

func ExpandField(permissions []interface{}) []string

func ExpandScopeSelector added in v0.2.13

func ExpandScopeSelector(scopeSelectors []interface{}) []nextgen.ScopeSelector

func ExpandTags added in v0.2.2

func ExpandTags(tags []interface{}) map[string]string

func FlattenDelgateSelectors added in v0.2.2

func FlattenDelgateSelectors(ds []string) []interface{}

func FlattenTags added in v0.2.2

func FlattenTags(tags map[string]string) []string

func GetDescriptionSchema added in v0.2.2

func GetDescriptionSchema(flag SchemaFlagType) *schema.Schema

func GetIdentifierSchema added in v0.2.2

func GetIdentifierSchema(flag SchemaFlagType) *schema.Schema

func GetNameSchema added in v0.2.2

func GetNameSchema(flag SchemaFlagType) *schema.Schema

func GetOrgIdSchema added in v0.2.2

func GetOrgIdSchema(flag SchemaFlagType) *schema.Schema

func GetProjectIdSchema added in v0.2.2

func GetProjectIdSchema(flag SchemaFlagType) *schema.Schema

func GetTagsSchema added in v0.2.2

func GetTagsSchema(flag SchemaFlagType) *schema.Schema

func HandleApiError added in v0.2.2

func HandleApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics

func HandleDBOpsApiError added in v0.31.8

func HandleDBOpsApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics

func HandleDBOpsReadApiError added in v0.31.8

func HandleDBOpsReadApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics

func HandleReadApiError added in v0.11.0

func HandleReadApiError(err error, d *schema.ResourceData, httpResp *http.Response) diag.Diagnostics

func MergeSchemas

func MergeSchemas(src map[string]*schema.Schema, dest map[string]*schema.Schema)

func SetCommonDataSourceSchema added in v0.2.2

func SetCommonDataSourceSchema(s map[string]*schema.Schema)

SetCommonDataSourceSchema sets the default schema objects used for most data sources.

func SetCommonDataSourceSchemaIdentifierRequired added in v0.14.5

func SetCommonDataSourceSchemaIdentifierRequired(s map[string]*schema.Schema)

func SetCommonDataSourceSchemaWRequired added in v0.17.1

func SetCommonDataSourceSchemaWRequired(s map[string]*schema.Schema)

func SetCommonResourceSchema added in v0.2.2

func SetCommonResourceSchema(s map[string]*schema.Schema)

SetCommonResourceSchema sets the default schema objects used for most resources.

func SetMultiLevelDatasourceSchema added in v0.2.2

func SetMultiLevelDatasourceSchema(s map[string]*schema.Schema)

func SetMultiLevelDatasourceSchemaIdentifierRequired added in v0.14.5

func SetMultiLevelDatasourceSchemaIdentifierRequired(s map[string]*schema.Schema)

func SetMultiLevelDatasourceSchemaWithoutCommonFields added in v0.30.5

func SetMultiLevelDatasourceSchemaWithoutCommonFields(s map[string]*schema.Schema)

func SetMultiLevelResourceSchema added in v0.2.2

func SetMultiLevelResourceSchema(s map[string]*schema.Schema)

func SetOptionalOrgAndProjectLevelDataSourceSchema added in v0.30.3

func SetOptionalOrgAndProjectLevelDataSourceSchema(s map[string]*schema.Schema)

func SetOrgLevelDataSourceSchema added in v0.2.2

func SetOrgLevelDataSourceSchema(s map[string]*schema.Schema)

func SetOrgLevelDataSourceSchemaIdentifierRequired added in v0.31.8

func SetOrgLevelDataSourceSchemaIdentifierRequired(s map[string]*schema.Schema)

func SetOrgLevelResourceSchema added in v0.2.2

func SetOrgLevelResourceSchema(s map[string]*schema.Schema)

SetOrgLevelResourceSchema sets the default schema objects used for org level resources.

func SetProjectLevelDataSourceSchema added in v0.2.2

func SetProjectLevelDataSourceSchema(s map[string]*schema.Schema)

func SetProjectLevelDataSourceSchemaIdentifierRequired added in v0.31.8

func SetProjectLevelDataSourceSchemaIdentifierRequired(s map[string]*schema.Schema)

func SetProjectLevelResourceSchema added in v0.2.2

func SetProjectLevelResourceSchema(s map[string]*schema.Schema)

SetProjectLevelResourceSchema sets the default schema objects used for project level resources.

func SetSchemaFlagType added in v0.2.2

func SetSchemaFlagType(s *schema.Schema, flag SchemaFlagType)

func YamlDiffSuppressFunction added in v0.29.3

func YamlDiffSuppressFunction(k, old, new string, d *schema.ResourceData) bool

YamlDiffSuppressFunction returns true if two content of yaml strings are identical. That helps to avoid unnecessary changes in plan if the yaml format was changed only, but not the data.

Types

type Desc added in v0.16.1

type Desc string

func (Desc) String added in v0.16.1

func (e Desc) String() string

type SchemaFlagType added in v0.2.2

type SchemaFlagType string

func (SchemaFlagType) String added in v0.2.2

func (e SchemaFlagType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL