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


Golang ResourceData.SetPartial方法代碼示例

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


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

示例1: setAllowAccessAttribute

func setAllowAccessAttribute(
	d *schema.ResourceData,
	database_server *brightbox.DatabaseServer,
) {
	d.Set("allow_access", database_server.AllowAccess)
	d.SetPartial("allow_access")
}
開發者ID:brightbox,項目名稱:terraform-provider-brightbox,代碼行數:7,代碼來源:resource_brightbox_database_server.go

示例2: resourceAwsSubnetUpdate

func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
	ec2conn := meta.(*AWSClient).ec2conn

	d.Partial(true)

	if err := setTags(ec2conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	if d.HasChange("map_public_ip_on_launch") {
		modifyOpts := &ec2.ModifySubnetAttribute{
			SubnetId:            d.Id(),
			MapPublicIpOnLaunch: true,
		}

		log.Printf("[DEBUG] Subnet modify attributes: %#v", modifyOpts)

		_, err := ec2conn.ModifySubnetAttribute(modifyOpts)

		if err != nil {
			return err
		} else {
			d.SetPartial("map_public_ip_on_launch")
		}
	}

	d.Partial(false)

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

示例3: resourceAwsProxyProtocolPolicyCreate

func resourceAwsProxyProtocolPolicyCreate(d *schema.ResourceData, meta interface{}) error {
	elbconn := meta.(*AWSClient).elbconn
	elbname := aws.String(d.Get("load_balancer").(string))

	input := &elb.CreateLoadBalancerPolicyInput{
		LoadBalancerName: elbname,
		PolicyAttributes: []*elb.PolicyAttribute{
			&elb.PolicyAttribute{
				AttributeName:  aws.String("ProxyProtocol"),
				AttributeValue: aws.String("True"),
			},
		},
		PolicyName:     aws.String("TFEnableProxyProtocol"),
		PolicyTypeName: aws.String("ProxyProtocolPolicyType"),
	}

	// Create a policy
	log.Printf("[DEBUG] ELB create a policy %s from policy type %s",
		*input.PolicyName, *input.PolicyTypeName)

	if _, err := elbconn.CreateLoadBalancerPolicy(input); err != nil {
		return fmt.Errorf("Error creating a policy %s: %s",
			*input.PolicyName, err)
	}

	// Assign the policy name for use later
	d.Partial(true)
	d.SetId(fmt.Sprintf("%s:%s", *elbname, *input.PolicyName))
	d.SetPartial("load_balancer")
	log.Printf("[INFO] ELB PolicyName: %s", *input.PolicyName)

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

示例4: resourceAwsAmiCopyCreate

func resourceAwsAmiCopyCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*AWSClient).ec2conn

	req := &ec2.CopyImageInput{
		Name:          aws.String(d.Get("name").(string)),
		Description:   aws.String(d.Get("description").(string)),
		SourceImageId: aws.String(d.Get("source_ami_id").(string)),
		SourceRegion:  aws.String(d.Get("source_ami_region").(string)),
	}

	res, err := client.CopyImage(req)
	if err != nil {
		return err
	}

	id := *res.ImageId
	d.SetId(id)
	d.Partial(true) // make sure we record the id even if the rest of this gets interrupted
	d.Set("id", id)
	d.Set("manage_ebs_snapshots", true)
	d.SetPartial("id")
	d.SetPartial("manage_ebs_snapshots")
	d.Partial(false)

	_, err = resourceAwsAmiWaitForAvailable(id, client)
	if err != nil {
		return err
	}

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

示例5: resourceAwsInstanceUpdate

func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
	ec2conn := meta.(*AWSClient).ec2conn

	modify := false
	opts := new(ec2.ModifyInstance)

	if v, ok := d.GetOk("source_dest_check"); ok {
		opts.SourceDestCheck = v.(bool)
		opts.SetSourceDestCheck = true
		modify = true
	}

	if modify {
		log.Printf("[INFO] Modifing instance %s: %#v", d.Id(), opts)
		if _, err := ec2conn.ModifyInstance(d.Id(), opts); err != nil {
			return err
		}

		// TODO(mitchellh): wait for the attributes we modified to
		// persist the change...
	}

	if err := setTags(ec2conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	return nil
}
開發者ID:packetloop,項目名稱:terraform,代碼行數:30,代碼來源:resource_aws_instance.go

示例6: resourceAwsInstanceUpdate

func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
	ec2conn := meta.(*AWSClient).ec2conn

	// SourceDestCheck can only be set on VPC instances
	if d.Get("subnet_id").(string) != "" {
		log.Printf("[INFO] Modifying instance %s", d.Id())
		err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeRequest{
			InstanceID: aws.String(d.Id()),
			SourceDestCheck: &ec2.AttributeBooleanValue{
				Value: aws.Boolean(d.Get("source_dest_check").(bool)),
			},
		})
		if err != nil {
			return err
		}
	}

	// TODO(mitchellh): wait for the attributes we modified to
	// persist the change...

	if err := setTags(ec2conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	return nil
}
開發者ID:pyhrus,項目名稱:terraform,代碼行數:28,代碼來源:resource_aws_instance.go

示例7: resourceAwsSecurityGroupUpdate

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

	sgRaw, _, err := SGStateRefreshFunc(conn, d.Id())()
	if err != nil {
		return err
	}
	if sgRaw == nil {
		d.SetId("")
		return nil
	}

	group := sgRaw.(*ec2.SecurityGroup)

	err = resourceAwsSecurityGroupUpdateRules(d, "ingress", meta, group)
	if err != nil {
		return err
	}

	if d.Get("vpc_id") != nil {
		err = resourceAwsSecurityGroupUpdateRules(d, "egress", meta, group)
		if err != nil {
			return err
		}
	}

	if err := setTags(conn, d); err != nil {
		return err
	}

	d.SetPartial("tags")

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

示例8: resourceAwsElbUpdate

func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
	elbconn := meta.(*AWSClient).elbconn

	d.Partial(true)

	// If we currently have instances, or did have instances,
	// we want to figure out what to add and remove from the load
	// balancer
	if d.HasChange("instances") {
		o, n := d.GetChange("instances")
		os := o.(*schema.Set)
		ns := n.(*schema.Set)
		remove := expandStringList(os.Difference(ns).List())
		add := expandStringList(ns.Difference(os).List())

		if len(add) > 0 {
			registerInstancesOpts := elb.RegisterInstancesWithLoadBalancer{
				LoadBalancerName: d.Id(),
				Instances:        add,
			}

			_, err := elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)
			if err != nil {
				return fmt.Errorf("Failure registering instances: %s", err)
			}
		}
		if len(remove) > 0 {
			deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancer{
				LoadBalancerName: d.Id(),
				Instances:        remove,
			}

			_, err := elbconn.DeregisterInstancesFromLoadBalancer(&deRegisterInstancesOpts)
			if err != nil {
				return fmt.Errorf("Failure deregistering instances: %s", err)
			}
		}

		d.SetPartial("instances")
	}

	log.Println("[INFO] outside modify attributes")
	if d.HasChange("cross_zone_load_balancing") {
		log.Println("[INFO] inside modify attributes")
		attrs := elb.ModifyLoadBalancerAttributes{
			LoadBalancerName: d.Get("name").(string),
			LoadBalancerAttributes: elb.LoadBalancerAttributes{
				CrossZoneLoadBalancingEnabled: d.Get("cross_zone_load_balancing").(bool),
			},
		}
		_, err := elbconn.ModifyLoadBalancerAttributes(&attrs)
		if err != nil {
			return fmt.Errorf("Failure configuring health check: %s", err)
		}
		d.SetPartial("cross_zone_load_balancing")
	}

	d.Partial(false)
	return resourceAwsElbRead(d, meta)
}
開發者ID:packetloop,項目名稱:terraform,代碼行數:60,代碼來源:resource_aws_elb.go

示例9: resourceAwsSubnetUpdate

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

	d.Partial(true)

	if err := setTags(conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	if d.HasChange("map_public_ip_on_launch") {
		modifyOpts := &ec2.ModifySubnetAttributeInput{
			SubnetId: aws.String(d.Id()),
			MapPublicIpOnLaunch: &ec2.AttributeBooleanValue{
				Value: aws.Bool(d.Get("map_public_ip_on_launch").(bool)),
			},
		}

		log.Printf("[DEBUG] Subnet modify attributes: %#v", modifyOpts)

		_, err := conn.ModifySubnetAttribute(modifyOpts)

		if err != nil {
			return err
		} else {
			d.SetPartial("map_public_ip_on_launch")
		}
	}

	d.Partial(false)

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

示例10: resourceAwsRoute53ZoneUpdate

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

	d.Partial(true)

	if d.HasChange("comment") {
		zoneInput := route53.UpdateHostedZoneCommentInput{
			Id:      aws.String(d.Id()),
			Comment: aws.String(d.Get("comment").(string)),
		}

		_, err := conn.UpdateHostedZoneComment(&zoneInput)
		if err != nil {
			return err
		} else {
			d.SetPartial("comment")
		}
	}

	if err := setTagsR53(conn, d, "hostedzone"); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	d.Partial(false)

	return resourceAwsRoute53ZoneRead(d, meta)
}
開發者ID:discogestalt,項目名稱:terraform,代碼行數:29,代碼來源:resource_aws_route53_zone.go

示例11: resourceAwsDirectoryServiceDirectoryUpdate

func resourceAwsDirectoryServiceDirectoryUpdate(d *schema.ResourceData, meta interface{}) error {
	dsconn := meta.(*AWSClient).dsconn

	if d.HasChange("enable_sso") {
		d.SetPartial("enable_sso")
		var err error

		if v, ok := d.GetOk("enable_sso"); ok && v.(bool) {
			log.Printf("[DEBUG] Enabling SSO for DS directory %q", d.Id())
			_, err = dsconn.EnableSso(&directoryservice.EnableSsoInput{
				DirectoryId: aws.String(d.Id()),
			})
		} else {
			log.Printf("[DEBUG] Disabling SSO for DS directory %q", d.Id())
			_, err = dsconn.DisableSso(&directoryservice.DisableSsoInput{
				DirectoryId: aws.String(d.Id()),
			})
		}

		if err != nil {
			return err
		}
	}

	return resourceAwsDirectoryServiceDirectoryRead(d, meta)
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:26,代碼來源:resource_aws_directory_service_directory.go

示例12: resourceAwsRouteTableUpdate

func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error {
	ec2conn := meta.(*AWSClient).ec2conn

	// Check if the route set as a whole has changed
	if d.HasChange("route") {
		o, n := d.GetChange("route")
		ors := o.(*schema.Set).Difference(n.(*schema.Set))
		nrs := n.(*schema.Set).Difference(o.(*schema.Set))

		// Now first loop through all the old routes and delete any obsolete ones
		for _, route := range ors.List() {
			m := route.(map[string]interface{})

			// Delete the route as it no longer exists in the config
			log.Printf(
				"[INFO] Deleting route from %s: %s",
				d.Id(), m["cidr_block"].(string))
			err := ec2conn.DeleteRoute(&ec2.DeleteRouteRequest{
				RouteTableID:         aws.String(d.Id()),
				DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
			})
			if err != nil {
				return err
			}
		}

		// Make sure we save the state of the currently configured rules
		routes := o.(*schema.Set).Intersection(n.(*schema.Set))
		d.Set("route", routes)

		// Then loop through al the newly configured routes and create them
		for _, route := range nrs.List() {
			m := route.(map[string]interface{})

			opts := ec2.CreateRouteRequest{
				RouteTableID:           aws.String(d.Id()),
				DestinationCIDRBlock:   aws.String(m["cidr_block"].(string)),
				GatewayID:              aws.String(m["gateway_id"].(string)),
				InstanceID:             aws.String(m["instance_id"].(string)),
				VPCPeeringConnectionID: aws.String(m["vpc_peering_connection_id"].(string)),
			}

			log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts)
			if err := ec2conn.CreateRoute(&opts); err != nil {
				return err
			}

			routes.Add(route)
			d.Set("route", routes)
		}
	}

	if err := setTags(ec2conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	return resourceAwsRouteTableRead(d, meta)
}
開發者ID:pyhrus,項目名稱:terraform,代碼行數:60,代碼來源:resource_aws_route_table.go

示例13: resourceAwsAmiUpdate

func resourceAwsAmiUpdate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*AWSClient).ec2conn

	d.Partial(true)

	if err := setTags(client, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	if d.Get("description").(string) != "" {
		_, err := client.ModifyImageAttribute(&ec2.ModifyImageAttributeInput{
			ImageId: aws.String(d.Id()),
			Description: &ec2.AttributeValue{
				Value: aws.String(d.Get("description").(string)),
			},
		})
		if err != nil {
			return err
		}
		d.SetPartial("description")
	}

	d.Partial(false)

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

示例14: resourceAwsVPCPeeringUpdate

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

	if err := setTags(conn, d); err != nil {
		return err
	} else {
		d.SetPartial("tags")
	}

	if _, ok := d.GetOk("auto_accept"); ok {
		pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())()

		if err != nil {
			return err
		}
		if pcRaw == nil {
			d.SetId("")
			return nil
		}
		pc := pcRaw.(*ec2.VpcPeeringConnection)

		if pc.Status != nil && *pc.Status.Code == "pending-acceptance" {
			status, err := resourceVPCPeeringConnectionAccept(conn, d.Id())
			if err != nil {
				return err
			}
			log.Printf(
				"[DEBUG] VPC Peering connection accept status: %s",
				status)
		}
	}

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

示例15: resourceCloudcaVolumeUpdate

func resourceCloudcaVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
	ccaClient := meta.(*cca.CcaClient)
	resources, _ := ccaClient.GetResources(d.Get("service_code").(string), d.Get("environment_name").(string))
	ccaResources := resources.(cloudca.Resources)

	d.Partial(true)
	if d.HasChange("instance_id") {
		oldInstanceId, newInstanceId := d.GetChange("instance_id")
		volume := &cloudca.Volume{
			Id: d.Id(),
		}
		if oldInstanceId != "" {
			err := ccaResources.Volumes.DetachFromInstance(volume)
			if err != nil {
				return err
			}
		}
		if newInstanceId != "" {
			err := ccaResources.Volumes.AttachToInstance(volume, newInstanceId.(string))
			if err != nil {
				return err
			}
		}
		d.SetPartial("instance_id")
	}
	d.Partial(false)
	return resourceCloudcaVolumeRead(d, meta)
}
開發者ID:cloud-ca,項目名稱:terraform-cloudca,代碼行數:28,代碼來源:resource_cloudca_volume.go


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