當前位置: 首頁>>代碼示例>>Golang>>正文


Golang config.NewRawConfig函數代碼示例

本文整理匯總了Golang中github.com/hashicorp/terraform/config.NewRawConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRawConfig函數的具體用法?Golang NewRawConfig怎麽用?Golang NewRawConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRawConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: loadConfigOutputs

func loadConfigOutputs(hclConfig *ast.ObjectList) ([]*tfcfg.Output, error) {
	hclConfig = hclConfig.Children()
	result := make([]*tfcfg.Output, 0, len(hclConfig.Items))

	if len(hclConfig.Items) == 0 {
		return result, nil
	}

	for _, item := range hclConfig.Items {
		n := item.Keys[0].Token.Value().(string)

		if _, ok := item.Val.(*ast.ObjectType); !ok {
			return nil, fmt.Errorf("output '%s': should be a block", n)
		}

		var config map[string]interface{}
		if err := hcl.DecodeObject(&config, item.Val); err != nil {
			return nil, err
		}

		rawConfig, err := tfcfg.NewRawConfig(config)
		if err != nil {
			return nil, fmt.Errorf(
				"error reading output config %s: %s", n, err,
			)
		}

		result = append(result, &tfcfg.Output{
			Name:      n,
			RawConfig: rawConfig,
		})
	}

	return result, nil
}
開發者ID:apparentlymart,項目名稱:padstone,代碼行數:35,代碼來源:config.go

示例2: FlattenGraph

// GraphNodeFlattenable impl.
func (n *graphNodeModuleExpanded) FlattenGraph() *Graph {
	graph := n.Subgraph()
	input := n.Original.Module.RawConfig

	// Go over each vertex and do some modifications to the graph for
	// flattening. We have to skip some nodes (graphNodeModuleSkippable)
	// as well as setup the variable values.
	for _, v := range graph.Vertices() {
		// If this is a variable, then look it up in the raw configuration.
		// If it exists in the raw configuration, set the value of it.
		if vn, ok := v.(*GraphNodeConfigVariable); ok && input != nil {
			key := vn.VariableName()
			if v, ok := input.Raw[key]; ok {
				config, err := config.NewRawConfig(map[string]interface{}{
					key: v,
				})
				if err != nil {
					// This shouldn't happen because it is already in
					// a RawConfig above meaning it worked once before.
					panic(err)
				}

				// Set the variable value so it is interpolated properly.
				// Also set the module so we set the value on it properly.
				vn.Module = graph.Path[len(graph.Path)-1]
				vn.Value = config
			}
		}
	}

	return graph
}
開發者ID:22Acacia,項目名稱:terraform-provider-googleappengine,代碼行數:33,代碼來源:graph_config_node_module.go

示例3: TestResourceProvider_Configure

func TestResourceProvider_Configure(t *testing.T) {
	rp := new(ResourceProvider)

	raw := map[string]interface{}{
		"token": "foo",
	}

	rawConfig, err := config.NewRawConfig(raw)
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	err = rp.Configure(terraform.NewResourceConfig(rawConfig))
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	expected := Config{
		Token: "foo",
	}

	if !reflect.DeepEqual(rp.Config, expected) {
		t.Fatalf("bad: %#v", rp.Config)
	}
}
開發者ID:EZTABLE,項目名稱:terraform,代碼行數:25,代碼來源:resource_provider_test.go

示例4: TestProviderConfigure

func TestProviderConfigure(t *testing.T) {
	p := Provider().(*schema.Provider)

	raw, err := config.NewRawConfig(map[string]interface{}{
		"account": helpers.TestAccount,
		"key":     helpers.TestKeyFile,
		"key_id":  helpers.TestKeyID,
		"url":     "https://us-east-1.api.joyentcloud.com",
	})
	if err != nil {
		t.Fatal(err)
	}
	providerConfig := terraform.NewResourceConfig(raw)

	assert.Nil(t, p.Meta())
	assert.Nil(t, p.Configure(providerConfig))

	config, ok := p.Meta().(*Config)
	if assert.True(t, ok) {
		assert.NotNil(t, config)
		assert.Equal(t, config.Account, helpers.TestAccount)
		assert.Equal(t, config.Key, helpers.TestKeyFile)
		assert.Equal(t, config.KeyID, helpers.TestKeyID)
		assert.Equal(t, config.URL, "https://us-east-1.api.joyentcloud.com")
	}
}
開發者ID:cehoffman,項目名稱:triton-terraform,代碼行數:26,代碼來源:provider_test.go

示例5: TestProviderConfigure

func TestProviderConfigure(t *testing.T) {
	var expectedKey string
	var expectedEmail string

	if v := os.Getenv("HEROKU_EMAIL"); v != "" {
		expectedEmail = v
	} else {
		expectedEmail = "foo"
	}

	if v := os.Getenv("HEROKU_API_KEY"); v != "" {
		expectedKey = v
	} else {
		expectedKey = "foo"
	}

	raw := map[string]interface{}{
		"api_key": expectedKey,
		"email":   expectedEmail,
	}

	rawConfig, err := config.NewRawConfig(raw)
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	rp := Provider()
	err = rp.Configure(terraform.NewResourceConfig(rawConfig))
	if err != nil {
		t.Fatalf("err: %s", err)
	}
}
開發者ID:EZTABLE,項目名稱:terraform,代碼行數:32,代碼來源:provider_test.go

示例6: TestResourceProvider_Configure

func TestResourceProvider_Configure(t *testing.T) {
	rp := new(ResourceProvider)

	raw := map[string]interface{}{
		"access_key": "foo",
		"secret_key": "bar",
		"region":     "us-east-1",
	}

	rawConfig, err := config.NewRawConfig(raw)
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	err = rp.Configure(terraform.NewResourceConfig(rawConfig))
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	expected := Config{
		AccessKey: "foo",
		SecretKey: "bar",
		Region:    "us-east-1",
	}

	if !reflect.DeepEqual(rp.Config, expected) {
		t.Fatalf("bad: %#v", rp.Config)
	}
}
開發者ID:jorgeng87,項目名稱:terraform,代碼行數:29,代碼來源:resource_provider_test.go

示例7: TestProviderValidate

func TestProviderValidate(t *testing.T) {
	cases := []struct {
		P      *Provider
		Config map[string]interface{}
		Err    bool
	}{
		{
			P: &Provider{
				Schema: map[string]*Schema{
					"foo": &Schema{},
				},
			},
			Config: nil,
			Err:    true,
		},
	}

	for i, tc := range cases {
		c, err := config.NewRawConfig(tc.Config)
		if err != nil {
			t.Fatalf("err: %s", err)
		}

		_, es := tc.P.Validate(terraform.NewResourceConfig(c))
		if len(es) > 0 != tc.Err {
			t.Fatalf("%d: %#v", i, es)
		}
	}
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:29,代碼來源:provider_test.go

示例8: TestProviderConfigure

func TestProviderConfigure(t *testing.T) {
	var expectedKey string

	if v := os.Getenv("MAILGUN_API_KEY"); v != "" {
		expectedKey = v
	} else {
		expectedKey = "foo"
	}

	raw := map[string]interface{}{
		"api_key": expectedKey,
	}

	rawConfig, err := config.NewRawConfig(raw)
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	rp := Provider()
	err = rp.Configure(terraform.NewResourceConfig(rawConfig))
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	config := rp.Meta().(*mailgun.Client)
	if config.ApiKey != expectedKey {
		t.Fatalf("bad: %#v", config)
	}
}
開發者ID:GeorgeErickson,項目名稱:terraform-1,代碼行數:29,代碼來源:provider_test.go

示例9: testConfig

func testConfig(t *testing.T, c map[string]interface{}) *terraform.ResourceConfig {
	r, err := config.NewRawConfig(c)
	if err != nil {
		t.Fatalf("bad: %s", err)
	}

	return terraform.NewResourceConfig(r)
}
開發者ID:Zordrak,項目名稱:terraform,代碼行數:8,代碼來源:resource_provisioner_test.go

示例10: testResourceConfig

func testResourceConfig(
	t *testing.T, c map[string]interface{}) *ResourceConfig {
	raw, err := config.NewRawConfig(c)
	if err != nil {
		t.Fatalf("err: %s", err)
	}

	return NewResourceConfig(raw)
}
開發者ID:BSick7,項目名稱:terraform,代碼行數:9,代碼來源:resource_test.go

示例11: loadConfigProviders

func loadConfigProviders(hclConfig *ast.ObjectList) ([]*tfcfg.ProviderConfig, error) {
	hclConfig = hclConfig.Children()
	result := make([]*tfcfg.ProviderConfig, 0, len(hclConfig.Items))

	if len(hclConfig.Items) == 0 {
		return result, nil
	}

	for _, item := range hclConfig.Items {
		n := item.Keys[0].Token.Value().(string)

		var listVal *ast.ObjectList
		if ot, ok := item.Val.(*ast.ObjectType); ok {
			listVal = ot.List
		} else {
			return nil, fmt.Errorf("provider '%s': should be a block", n)
		}

		var config map[string]interface{}
		if err := hcl.DecodeObject(&config, item.Val); err != nil {
			return nil, err
		}

		delete(config, "alias")

		rawConfig, err := tfcfg.NewRawConfig(config)
		if err != nil {
			return nil, fmt.Errorf(
				"error reading provider config %s: %s", n, err,
			)
		}

		// If we have an alias, add it in
		var alias string
		if a := listVal.Filter("alias"); len(a.Items) > 0 {
			err := hcl.DecodeObject(&alias, a.Items[0].Val)
			if err != nil {
				return nil, fmt.Errorf(
					"error reading provider %s alias: %s", n, err,
				)
			}
		}

		result = append(result, &tfcfg.ProviderConfig{
			Name:      n,
			Alias:     alias,
			RawConfig: rawConfig,
		})
	}

	return result, nil
}
開發者ID:apparentlymart,項目名稱:padstone,代碼行數:52,代碼來源:config.go

示例12: interpolateForce

// interpolateForce is a temporary thing. We want to get rid of interpolate
// above and likewise this, but it can only be done after the f-ast-graph
// refactor is complete.
func (c *ResourceConfig) interpolateForce() {
	if c.raw == nil {
		var err error
		c.raw, err = config.NewRawConfig(make(map[string]interface{}))
		if err != nil {
			panic(err)
		}
	}

	c.ComputedKeys = c.raw.UnknownKeys()
	c.Raw = c.raw.RawMap()
	c.Config = c.raw.Config()
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:16,代碼來源:resource.go

示例13: loadConfigModules

func loadConfigModules(hclConfig *ast.ObjectList) ([]*tfcfg.Module, error) {
	hclConfig = hclConfig.Children()
	result := make([]*tfcfg.Module, 0, len(hclConfig.Items))

	if len(hclConfig.Items) == 0 {
		return result, nil
	}

	for _, item := range hclConfig.Items {
		n := item.Keys[0].Token.Value().(string)

		var listVal *ast.ObjectList
		if ot, ok := item.Val.(*ast.ObjectType); ok {
			listVal = ot.List
		} else {
			return nil, fmt.Errorf("module '%s': should be a block", n)
		}

		var config map[string]interface{}
		if err := hcl.DecodeObject(&config, item.Val); err != nil {
			return nil, err
		}

		delete(config, "source")

		rawConfig, err := tfcfg.NewRawConfig(config)
		if err != nil {
			return nil, fmt.Errorf(
				"error reading module config %s: %s", n, err,
			)
		}

		var source string
		if a := listVal.Filter("source"); len(a.Items) > 0 {
			err := hcl.DecodeObject(&source, a.Items[0].Val)
			if err != nil {
				return nil, fmt.Errorf(
					"error reading module %s source: %s", n, err,
				)
			}
		}

		result = append(result, &tfcfg.Module{
			Name:      n,
			Source:    source,
			RawConfig: rawConfig,
		})
	}

	return result, nil
}
開發者ID:apparentlymart,項目名稱:padstone,代碼行數:51,代碼來源:config.go

示例14: testConfigInterpolate

func testConfigInterpolate(
	t *testing.T,
	raw map[string]interface{},
	vs map[string]ast.Variable) *terraform.ResourceConfig {
	rc, err := config.NewRawConfig(raw)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	if len(vs) > 0 {
		if err := rc.Interpolate(vs); err != nil {
			t.Fatalf("err: %s", err)
		}
	}

	return terraform.NewResourceConfig(rc)
}
開發者ID:morts1a,項目名稱:terraform,代碼行數:16,代碼來源:field_reader_config_test.go

示例15: TestAzure_providerConfigure

func TestAzure_providerConfigure(t *testing.T) {
	home, err := homedir.Dir()
	if err != nil {
		t.Fatalf("Error fetching homedir: %s", err)
	}
	fh, err := ioutil.TempFile(home, "tf-test-home")
	if err != nil {
		t.Fatalf("Error creating homedir-based temporary file: %s", err)
	}
	defer os.Remove(fh.Name())

	_, err = io.WriteString(fh, testAzurePublishSettingsStr)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	fh.Close()

	r := strings.NewReplacer(home, "~")
	homePath := r.Replace(fh.Name())

	cases := []struct {
		SettingsFile string // String of XML or a path to an XML file
		NilMeta      bool   // whether meta is expected to be nil
	}{
		{testAzurePublishSettingsStr, false},
		{homePath, false},
	}

	for _, tc := range cases {
		rp := Provider()
		raw := map[string]interface{}{
			"settings_file": tc.SettingsFile,
		}

		rawConfig, err := config.NewRawConfig(raw)
		if err != nil {
			t.Fatalf("err: %s", err)
		}

		err = rp.Configure(terraform.NewResourceConfig(rawConfig))
		meta := rp.(*schema.Provider).Meta()
		if (meta == nil) != tc.NilMeta {
			t.Fatalf("expected NilMeta: %t, got meta: %#v, settings_file: %q",
				tc.NilMeta, meta, tc.SettingsFile)
		}
	}
}
開發者ID:patrickdlee,項目名稱:terraform,代碼行數:47,代碼來源:provider_test.go


注:本文中的github.com/hashicorp/terraform/config.NewRawConfig函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。