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


Golang ResourceData.GetOk方法代碼示例

本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.GetOk方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.GetOk方法的具體用法?Golang ResourceData.GetOk怎麽用?Golang ResourceData.GetOk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hashicorp/terraform/helper/schema.ResourceData的用法示例。


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

示例1: resourceAwsVPCEndpointCreate

func resourceAwsVPCEndpointCreate(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).ec2conn
	input := &ec2.CreateVpcEndpointInput{
		VpcId:       aws.String(d.Get("vpc_id").(string)),
		ServiceName: aws.String(d.Get("service_name").(string)),
	}

	if v, ok := d.GetOk("route_table_ids"); ok {
		list := v.(*schema.Set).List()
		if len(list) > 0 {
			input.RouteTableIds = expandStringList(list)
		}
	}

	if v, ok := d.GetOk("policy"); ok {
		policy, err := normalizeJsonString(v)
		if err != nil {
			return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
		}
		input.PolicyDocument = aws.String(policy)
	}

	log.Printf("[DEBUG] Creating VPC Endpoint: %#v", input)
	output, err := conn.CreateVpcEndpoint(input)
	if err != nil {
		return fmt.Errorf("Error creating VPC Endpoint: %s", err)
	}
	log.Printf("[DEBUG] VPC Endpoint %q created.", *output.VpcEndpoint.VpcEndpointId)

	d.SetId(*output.VpcEndpoint.VpcEndpointId)

	return resourceAwsVPCEndpointRead(d, meta)
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:33,代碼來源:resource_aws_vpc_endpoint.go

示例2: getImageIDFromConfig

func getImageIDFromConfig(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) (string, error) {
	// If block_device was used, an Image does not need to be specified.
	// If an Image was specified, ignore it
	if _, ok := d.GetOk("block_device"); ok {
		return "", nil
	}

	if imageId := d.Get("image_id").(string); imageId != "" {
		return imageId, nil
	} else {
		// try the OS_IMAGE_ID environment variable
		if v := os.Getenv("OS_IMAGE_ID"); v != "" {
			return v, nil
		}
	}

	imageName := d.Get("image_name").(string)
	if imageName == "" {
		// try the OS_IMAGE_NAME environment variable
		if v := os.Getenv("OS_IMAGE_NAME"); v != "" {
			imageName = v
		}
	}

	if imageName != "" {
		imageId, err := images.IDFromName(computeClient, imageName)
		if err != nil {
			return "", err
		}
		return imageId, nil
	}

	return "", fmt.Errorf("Neither a boot device, image ID, or image name were able to be determined.")
}
開發者ID:MattiasGees,項目名稱:terraform,代碼行數:34,代碼來源:resource_openstack_compute_instance_v2.go

示例3: checkVolumeConfig

func checkVolumeConfig(d *schema.ResourceData) error {
	// Although a volume_id is required to attach a volume, in order to be able to report
	// the attached volumes of an instance, it must be "computed" and thus "optional".
	// This accounts for situations such as "boot from volume" as well as volumes being
	// attached to the instance outside of Terraform.
	if v := d.Get("volume"); v != nil {
		vols := v.(*schema.Set).List()
		if len(vols) > 0 {
			for _, v := range vols {
				va := v.(map[string]interface{})
				if va["volume_id"].(string) == "" {
					return fmt.Errorf("A volume_id must be specified when attaching volumes.")
				}
			}
		}
	}

	if vL, ok := d.GetOk("block_device"); ok {
		if len(vL.([]interface{})) > 1 {
			return fmt.Errorf("Can only specify one block device to boot from.")
		}
	}

	return nil
}
開發者ID:MattiasGees,項目名稱:terraform,代碼行數:25,代碼來源:resource_openstack_compute_instance_v2.go

示例4: resourceCloudFlareRecordCreate

func resourceCloudFlareRecordCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*cloudflare.Client)

	// Create the new record
	newRecord := &cloudflare.CreateRecord{
		Name:    d.Get("name").(string),
		Type:    d.Get("type").(string),
		Content: d.Get("value").(string),
	}

	if ttl, ok := d.GetOk("ttl"); ok {
		newRecord.Ttl = ttl.(string)
	}

	if priority, ok := d.GetOk("priority"); ok {
		newRecord.Priority = priority.(string)
	}

	log.Printf("[DEBUG] CloudFlare Record create configuration: %#v", newRecord)

	rec, err := client.CreateRecord(d.Get("domain").(string), newRecord)

	if err != nil {
		return fmt.Errorf("Failed to create CloudFlare Record: %s", err)
	}

	d.SetId(rec.Id)
	log.Printf("[INFO] CloudFlare Record ID: %s", d.Id())

	return resourceCloudFlareRecordRead(d, meta)
}
開發者ID:solarnz,項目名稱:terraform,代碼行數:31,代碼來源:resource_cloudflare_record.go

示例5: resourceDigitalOceanFloatingIpCreate

func resourceDigitalOceanFloatingIpCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*godo.Client)

	log.Printf("[INFO] Create a FloatingIP In a Region")
	regionOpts := &godo.FloatingIPCreateRequest{
		Region: d.Get("region").(string),
	}

	log.Printf("[DEBUG] FloatingIP Create: %#v", regionOpts)
	floatingIp, _, err := client.FloatingIPs.Create(regionOpts)
	if err != nil {
		return fmt.Errorf("Error creating FloatingIP: %s", err)
	}

	d.SetId(floatingIp.IP)

	if v, ok := d.GetOk("droplet_id"); ok {

		log.Printf("[INFO] Assigning the Floating IP to the Droplet %d", v.(int))
		action, _, err := client.FloatingIPActions.Assign(d.Id(), v.(int))
		if err != nil {
			return fmt.Errorf(
				"Error Assigning FloatingIP (%s) to the droplet: %s", d.Id(), err)
		}

		_, unassignedErr := waitForFloatingIPReady(d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
		if unassignedErr != nil {
			return fmt.Errorf(
				"Error waiting for FloatingIP (%s) to be Assigned: %s", d.Id(), unassignedErr)
		}
	}

	return resourceDigitalOceanFloatingIpRead(d, meta)
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:34,代碼來源:resource_digitalocean_floating_ip.go

示例6: resourceAWSEbsVolumeUpdate

func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).ec2conn
	if _, ok := d.GetOk("tags"); ok {
		setTags(conn, d)
	}
	return resourceAwsEbsVolumeRead(d, meta)
}
開發者ID:discogestalt,項目名稱:terraform,代碼行數:7,代碼來源:resource_aws_ebs_volume.go

示例7: resourceAwsApiGatewayMethodCreate

func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).apigateway

	models := make(map[string]string)
	for k, v := range d.Get("request_models").(map[string]interface{}) {
		models[k] = v.(string)
	}

	parameters := make(map[string]bool)
	if parameterData, ok := d.GetOk("request_parameters"); ok {
		params := parameterData.(*schema.Set).List()
		for k := range params {
			parameters[params[k].(string)] = true
		}
	}

	_, err := conn.PutMethod(&apigateway.PutMethodInput{
		AuthorizationType: aws.String(d.Get("authorization").(string)),
		HttpMethod:        aws.String(d.Get("http_method").(string)),
		ResourceId:        aws.String(d.Get("resource_id").(string)),
		RestApiId:         aws.String(d.Get("rest_api_id").(string)),
		RequestModels:     aws.StringMap(models),
		// TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented
		RequestParameters: nil,
		ApiKeyRequired:    aws.Bool(d.Get("api_key_required").(bool)),
	})
	if err != nil {
		return fmt.Errorf("Error creating API Gateway Method: %s", err)
	}

	d.SetId(fmt.Sprintf("agm-%s-%s-%s", d.Get("rest_api_id").(string), d.Get("resource_id").(string), d.Get("http_method").(string)))
	log.Printf("[DEBUG] API Gateway Method ID: %s", d.Id())

	return nil
}
開發者ID:discogestalt,項目名稱:terraform,代碼行數:35,代碼來源:resource_aws_api_gateway_method.go

示例8: getOptionalRegion

func getOptionalRegion(d *schema.ResourceData, config *Config) string {
	if res, ok := d.GetOk("region"); !ok {
		return config.Region
	} else {
		return res.(string)
	}
}
開發者ID:saulshanabrook,項目名稱:terraform,代碼行數:7,代碼來源:resource_compute_address.go

示例9: resourceComputeSslCertificateCreate

func resourceComputeSslCertificateCreate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	project, err := getProject(d, config)
	if err != nil {
		return err
	}

	// Build the certificate parameter
	cert := &compute.SslCertificate{
		Name:        d.Get("name").(string),
		Certificate: d.Get("certificate").(string),
		PrivateKey:  d.Get("private_key").(string),
	}

	if v, ok := d.GetOk("description"); ok {
		cert.Description = v.(string)
	}

	op, err := config.clientCompute.SslCertificates.Insert(
		project, cert).Do()

	if err != nil {
		return fmt.Errorf("Error creating ssl certificate: %s", err)
	}

	err = computeOperationWaitGlobal(config, op, project, "Creating SslCertificate")
	if err != nil {
		return err
	}

	d.SetId(cert.Name)

	return resourceComputeSslCertificateRead(d, meta)
}
開發者ID:Originate,項目名稱:terraform,代碼行數:35,代碼來源:resource_compute_ssl_certificate.go

示例10: providerConfigure

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
	config := Config{
		AccessKey:        d.Get("access_key").(string),
		SecretKey:        d.Get("secret_key").(string),
		Profile:          d.Get("profile").(string),
		CredsFilename:    d.Get("shared_credentials_file").(string),
		Token:            d.Get("token").(string),
		Region:           d.Get("region").(string),
		MaxRetries:       d.Get("max_retries").(int),
		DynamoDBEndpoint: d.Get("dynamodb_endpoint").(string),
		KinesisEndpoint:  d.Get("kinesis_endpoint").(string),
		Insecure:         d.Get("insecure").(bool),
	}

	endpointsSet := d.Get("endpoints").(*schema.Set)

	for _, endpointsSetI := range endpointsSet.List() {
		endpoints := endpointsSetI.(map[string]interface{})
		config.IamEndpoint = endpoints["iam"].(string)
		config.Ec2Endpoint = endpoints["ec2"].(string)
		config.ElbEndpoint = endpoints["elb"].(string)
	}

	if v, ok := d.GetOk("allowed_account_ids"); ok {
		config.AllowedAccountIds = v.(*schema.Set).List()
	}

	if v, ok := d.GetOk("forbidden_account_ids"); ok {
		config.ForbiddenAccountIds = v.(*schema.Set).List()
	}

	return config.Client()
}
開發者ID:kwoods,項目名稱:terraform,代碼行數:33,代碼來源:provider.go

示例11: resourceCloudStackAffinityGroupCreate

func resourceCloudStackAffinityGroupCreate(d *schema.ResourceData, meta interface{}) error {
	cs := meta.(*cloudstack.CloudStackClient)

	name := d.Get("name").(string)
	affinityGroupType := d.Get("type").(string)

	// Create a new parameter struct
	p := cs.AffinityGroup.NewCreateAffinityGroupParams(name, affinityGroupType)

	// Set the description
	if description, ok := d.GetOk("description"); ok {
		p.SetDescription(description.(string))
	} else {
		p.SetDescription(name)
	}

	// If there is a project supplied, we retrieve and set the project id
	if err := setProjectid(p, cs, d); err != nil {
		return err
	}

	log.Printf("[DEBUG] Creating affinity group %s", name)
	r, err := cs.AffinityGroup.CreateAffinityGroup(p)
	if err != nil {
		return err
	}

	log.Printf("[DEBUG] Affinity group %s successfully created", name)
	d.SetId(r.Id)

	return resourceCloudStackAffinityGroupRead(d, meta)
}
開發者ID:partamonov,項目名稱:terraform,代碼行數:32,代碼來源:resource_cloudstack_affinity_group.go

示例12: buildNetworks

func buildNetworks(d *schema.ResourceData, meta interface{}) (error, []*compute.NetworkInterface) {
	// Build up the list of networks
	networksCount := d.Get("network_interface.#").(int)
	networkInterfaces := make([]*compute.NetworkInterface, 0, networksCount)
	for i := 0; i < networksCount; i++ {
		prefix := fmt.Sprintf("network_interface.%d", i)

		source := "global/networks/default"
		if v, ok := d.GetOk(prefix + ".network"); ok {
			if v.(string) != "default" {
				source = v.(string)
			}
		}

		// Build the networkInterface
		var iface compute.NetworkInterface
		iface.Network = source

		accessConfigsCount := d.Get(prefix + ".access_config.#").(int)
		iface.AccessConfigs = make([]*compute.AccessConfig, accessConfigsCount)
		for j := 0; j < accessConfigsCount; j++ {
			acPrefix := fmt.Sprintf("%s.access_config.%d", prefix, j)
			iface.AccessConfigs[j] = &compute.AccessConfig{
				Type:  "ONE_TO_ONE_NAT",
				NatIP: d.Get(acPrefix + ".nat_ip").(string),
			}
		}

		networkInterfaces = append(networkInterfaces, &iface)
	}
	return nil, networkInterfaces
}
開發者ID:rgl,項目名稱:terraform,代碼行數:32,代碼來源:resource_compute_instance_template.go

示例13: resourceProfitBricksDatacenterCreate

func resourceProfitBricksDatacenterCreate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	profitbricks.SetAuth(config.Username, config.Password)

	datacenter := profitbricks.Datacenter{
		Properties: profitbricks.DatacenterProperties{
			Name:     d.Get("name").(string),
			Location: d.Get("location").(string),
		},
	}

	if attr, ok := d.GetOk("description"); ok {
		datacenter.Properties.Description = attr.(string)
	}
	dc := profitbricks.CreateDatacenter(datacenter)

	if dc.StatusCode > 299 {
		return fmt.Errorf(
			"Error creating data center (%s) (%s)", d.Id(), dc.Response)
	}
	d.SetId(dc.Id)

	log.Printf("[INFO] DataCenter Id: %s", d.Id())

	err := waitTillProvisioned(meta, dc.Headers.Get("Location"))
	if err != nil {
		return err
	}
	return resourceProfitBricksDatacenterRead(d, meta)
}
開發者ID:hashicorp,項目名稱:terraform,代碼行數:30,代碼來源:resource_profitbricks_datacenter.go

示例14: resourceComputeTargetHttpProxyCreate

func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)

	proxy := &compute.TargetHttpProxy{
		Name:   d.Get("name").(string),
		UrlMap: d.Get("url_map").(string),
	}

	if v, ok := d.GetOk("description"); ok {
		proxy.Description = v.(string)
	}

	log.Printf("[DEBUG] TargetHttpProxy insert request: %#v", proxy)
	op, err := config.clientCompute.TargetHttpProxies.Insert(
		config.Project, proxy).Do()
	if err != nil {
		return fmt.Errorf("Error creating TargetHttpProxy: %s", err)
	}

	err = computeOperationWaitGlobal(config, op, "Creating Target Http Proxy")
	if err != nil {
		return err
	}

	d.SetId(proxy.Name)

	return resourceComputeTargetHttpProxyRead(d, meta)
}
開發者ID:atomisthq,項目名稱:terraform,代碼行數:28,代碼來源:resource_compute_target_http_proxy.go

示例15: resourceCloudStackLoadBalancerRuleRead

func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) error {
	cs := meta.(*cloudstack.CloudStackClient)

	// Get the load balancer details
	lb, count, err := cs.LoadBalancer.GetLoadBalancerRuleByID(d.Id())
	if err != nil {
		if count == 0 {
			log.Printf("[DEBUG] Load balancer rule %s does no longer exist", d.Get("name").(string))
			d.SetId("")
			return nil
		}

		return err
	}

	d.Set("algorithm", lb.Algorithm)
	d.Set("public_port", lb.Publicport)
	d.Set("private_port", lb.Privateport)
	d.Set("ip_address_id", lb.Publicipid)

	// Only set network if user specified it to avoid spurious diffs
	_, networkID := d.GetOk("network_id")
	_, network := d.GetOk("network")
	if networkID || network {
		d.Set("network_id", lb.Networkid)
	}

	return nil
}
開發者ID:chandy,項目名稱:terraform,代碼行數:29,代碼來源:resource_cloudstack_loadbalancer_rule.go


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