本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.GetChange方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.GetChange方法的具體用法?Golang ResourceData.GetChange怎麽用?Golang ResourceData.GetChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.GetChange方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setTagsCloudtrail
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsCloudtrail(conn *cloudtrail.CloudTrail, d *schema.ResourceData) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsCloudtrail(tagsFromMapCloudtrail(o), tagsFromMapCloudtrail(n))
// Set tags
if len(remove) > 0 {
input := cloudtrail.RemoveTagsInput{
ResourceId: aws.String(d.Get("arn").(string)),
TagsList: remove,
}
log.Printf("[DEBUG] Removing CloudTrail tags: %s", input)
_, err := conn.RemoveTags(&input)
if err != nil {
return err
}
}
if len(create) > 0 {
input := cloudtrail.AddTagsInput{
ResourceId: aws.String(d.Get("arn").(string)),
TagsList: create,
}
log.Printf("[DEBUG] Adding CloudTrail tags: %s", input)
_, err := conn.AddTags(&input)
if err != nil {
return err
}
}
}
return nil
}
示例2: resourceAwsVpnGatewayDetach
func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
// Get the old VPC ID to detach from
vpcID, _ := d.GetChange("vpc_id")
if vpcID.(string) == "" {
log.Printf(
"[DEBUG] Not detaching VPN Gateway '%s' as no VPC ID is set",
d.Id())
return nil
}
log.Printf(
"[INFO] Detaching VPN Gateway '%s' from VPC '%s'",
d.Id(),
vpcID.(string))
wait := true
_, err := conn.DetachVpnGateway(&ec2.DetachVpnGatewayInput{
VpnGatewayId: aws.String(d.Id()),
VpcId: aws.String(vpcID.(string)),
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok {
if ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
err = nil
wait = false
} else if ec2err.Code() == "InvalidVpnGatewayAttachment.NotFound" {
err = nil
wait = false
}
}
if err != nil {
return err
}
}
if !wait {
return nil
}
// Wait for it to be fully detached before continuing
log.Printf("[DEBUG] Waiting for VPN gateway (%s) to detach", d.Id())
stateConf := &resource.StateChangeConf{
Pending: []string{"attached", "detaching", "available"},
Target: []string{"detached"},
Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "detached"),
Timeout: 1 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf(
"Error waiting for vpn gateway (%s) to detach: %s",
d.Id(), err)
}
return nil
}
示例3: resourceAwsEcsServiceUpdate
func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecsconn
log.Printf("[DEBUG] Updating ECS service %s", d.Id())
input := ecs.UpdateServiceInput{
Service: aws.String(d.Id()),
Cluster: aws.String(d.Get("cluster").(string)),
}
if d.HasChange("desired_count") {
_, n := d.GetChange("desired_count")
input.DesiredCount = aws.Int64(int64(n.(int)))
}
if d.HasChange("task_definition") {
_, n := d.GetChange("task_definition")
input.TaskDefinition = aws.String(n.(string))
}
if d.HasChange("deployment_maximum_percent") || d.HasChange("deployment_minimum_healthy_percent") {
input.DeploymentConfiguration = &ecs.DeploymentConfiguration{
MaximumPercent: aws.Int64(int64(d.Get("deployment_maximum_percent").(int))),
MinimumHealthyPercent: aws.Int64(int64(d.Get("deployment_minimum_healthy_percent").(int))),
}
}
out, err := conn.UpdateService(&input)
if err != nil {
return err
}
service := out.Service
log.Printf("[DEBUG] Updated ECS service %s", service)
return resourceAwsEcsServiceRead(d, meta)
}
示例4: resourceProfitBricksLanUpdate
func resourceProfitBricksLanUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
profitbricks.SetAuth(config.Username, config.Password)
properties := &profitbricks.LanProperties{}
if d.HasChange("public") {
_, newValue := d.GetChange("public")
properties.Public = newValue.(bool)
}
if d.HasChange("name") {
_, newValue := d.GetChange("name")
properties.Name = newValue.(string)
}
log.Printf("[DEBUG] LAN UPDATE: %s : %s", properties, d.Get("name"))
if properties != nil {
lan := profitbricks.PatchLan(d.Get("datacenter_id").(string), d.Id(), *properties)
if lan.StatusCode > 299 {
return fmt.Errorf("An error occured while patching a lan ID %s %s", d.Id(), lan.Response)
}
err := waitTillProvisioned(meta, lan.Headers.Get("Location"))
if err != nil {
return err
}
}
return resourceProfitBricksLanRead(d, meta)
}
示例5: resourceVultrServerUpdate
func resourceVultrServerUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*lib.Client)
d.Partial(true)
if d.HasChange("name") {
oldName, newName := d.GetChange("name")
err := client.RenameServer(d.Id(), newName.(string))
if err != nil {
return fmt.Errorf("Error renaming server (%s): %s", d.Id(), err)
}
_, err = WaitForServerAttribute(d, newName.(string), []string{"", oldName.(string)}, "name", meta)
if err != nil {
return fmt.Errorf("Error waiting for rename server (%s) to finish: %s", d.Id(), err)
}
d.SetPartial("name")
}
return resourceVultrServerRead(d, meta)
}
示例6: resourceAwsSqsQueueUpdate
func resourceAwsSqsQueueUpdate(d *schema.ResourceData, meta interface{}) error {
sqsconn := meta.(*AWSClient).sqsconn
attributes := make(map[string]*string)
resource := *resourceAwsSqsQueue()
for k, s := range resource.Schema {
if attrKey, ok := AttributeMap[k]; ok {
if d.HasChange(k) {
log.Printf("[DEBUG] Updating %s", attrKey)
_, n := d.GetChange(k)
if s.Type == schema.TypeInt {
attributes[attrKey] = aws.String(strconv.Itoa(n.(int)))
} else {
attributes[attrKey] = aws.String(n.(string))
}
}
}
}
if len(attributes) > 0 {
req := &sqs.SetQueueAttributesInput{
QueueUrl: aws.String(d.Id()),
Attributes: attributes,
}
sqsconn.SetQueueAttributes(req)
}
return resourceAwsSqsQueueRead(d, meta)
}
示例7: resourceAwsElasticBeanstalkEnvironmentOptionSettingsUpdate
func resourceAwsElasticBeanstalkEnvironmentOptionSettingsUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error {
name := d.Get("name").(string)
envId := d.Id()
log.Printf("[DEBUG] Elastic Beanstalk application: %s, update options", name)
req := &elasticbeanstalk.UpdateEnvironmentInput{
EnvironmentId: aws.String(envId),
}
if d.HasChange("setting") {
o, n := d.GetChange("setting")
if o == nil {
o = &schema.Set{F: optionSettingValueHash}
}
if n == nil {
n = &schema.Set{F: optionSettingValueHash}
}
os := o.(*schema.Set)
ns := n.(*schema.Set)
req.OptionSettings = extractOptionSettings(ns.Difference(os))
}
if _, err := conn.UpdateEnvironment(req); err != nil {
return err
}
return nil
}
示例8: resourceAwsInspectorAssessmentTargetUpdate
func resourceAwsInspectorAssessmentTargetUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).inspectorconn
input := inspector.UpdateAssessmentTargetInput{
AssessmentTargetArn: aws.String(d.Id()),
}
if d.HasChange("name") {
_, n := d.GetChange("name")
input.AssessmentTargetName = aws.String(n.(string))
}
if d.HasChange("resource_group_arn") {
_, n := d.GetChange("resource_group_arn")
input.AssessmentTargetName = aws.String(n.(string))
}
_, err := conn.UpdateAssessmentTarget(&input)
if err != nil {
return err
}
log.Println("[DEBUG] Inspector Assessment Target updated")
return resourceAwsInspectorAssessmentTargetRead(d, meta)
}
示例9: setTags
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTags(tagsFromMap(o), tagsFromMap(n))
// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove)
err := conn.DeleteTags(&ec2.DeleteTagsRequest{
Resources: []string{d.Id()},
Tags: remove,
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
err := conn.CreateTags(&ec2.CreateTagsRequest{
Resources: []string{d.Id()},
Tags: create,
})
if err != nil {
return err
}
}
}
return nil
}
示例10: setTagsS3
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsS3(conn *s3.S3, d *schema.ResourceData) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsS3(tagsFromMapS3(o), tagsFromMapS3(n))
// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove)
_, err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{
Bucket: aws.String(d.Get("bucket").(string)),
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
req := &s3.PutBucketTaggingInput{
Bucket: aws.String(d.Get("bucket").(string)),
Tagging: &s3.Tagging{
TagSet: create,
},
}
_, err := conn.PutBucketTagging(req)
if err != nil {
return err
}
}
}
return nil
}
示例11: UpdatePermissions
func UpdatePermissions(d *schema.ResourceData, meta interface{}) error {
rmqc := meta.(*rabbithole.Client)
permissionId := strings.Split(d.Id(), "@")
if len(permissionId) < 2 {
return fmt.Errorf("Unable to determine Permission ID")
}
user := permissionId[0]
vhost := permissionId[1]
if d.HasChange("permissions") {
_, newPerms := d.GetChange("permissions")
newPermsList := newPerms.([]interface{})
permsMap, ok := newPermsList[0].(map[string]interface{})
if !ok {
return fmt.Errorf("Unable to parse permissions")
}
if err := setPermissionsIn(rmqc, vhost, user, permsMap); err != nil {
return err
}
}
return ReadPermissions(d, meta)
}
示例12: setTags
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTags(cs *cloudstack.CloudStackClient, d *schema.ResourceData, resourcetype string) error {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
remove, create := diffTags(tagsFromSchema(o), tagsFromSchema(n))
log.Printf("[DEBUG] tags to remove: %v", remove)
log.Printf("[DEBUG] tags to create: %v", create)
// First remove any obsolete tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %v from %s", remove, d.Id())
p := cs.Resourcetags.NewDeleteTagsParams([]string{d.Id()}, resourcetype)
p.SetTags(remove)
_, err := cs.Resourcetags.DeleteTags(p)
if err != nil {
return err
}
}
// Then add any new tags
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %v for %s", create, d.Id())
p := cs.Resourcetags.NewCreateTagsParams([]string{d.Id()}, resourcetype, create)
_, err := cs.Resourcetags.CreateTags(p)
if err != nil {
return err
}
}
return nil
}
示例13: 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)
}
示例14: resourceAwsSqsQueueUpdate
func resourceAwsSqsQueueUpdate(d *schema.ResourceData, meta interface{}) error {
sqsconn := meta.(*AWSClient).sqsconn
attributes := make(map[string]*string)
resource := *resourceAwsSqsQueue()
for k, s := range resource.Schema {
if attrKey, ok := AttributeMap[k]; ok {
if d.HasChange(k) {
log.Printf("[DEBUG] Updating %s", attrKey)
_, n := d.GetChange(k)
switch s.Type {
case schema.TypeInt:
attributes[attrKey] = aws.String(strconv.Itoa(n.(int)))
case schema.TypeBool:
attributes[attrKey] = aws.String(strconv.FormatBool(n.(bool)))
default:
attributes[attrKey] = aws.String(n.(string))
}
}
}
}
if len(attributes) > 0 {
req := &sqs.SetQueueAttributesInput{
QueueUrl: aws.String(d.Id()),
Attributes: attributes,
}
if _, err := sqsconn.SetQueueAttributes(req); err != nil {
return fmt.Errorf("[ERR] Error updating SQS attributes: %s", err)
}
}
return resourceAwsSqsQueueRead(d, meta)
}
示例15: Update
func (lt *opsworksLayerType) Update(d *schema.ResourceData, client *opsworks.OpsWorks) error {
req := &opsworks.UpdateLayerInput{
LayerId: aws.String(d.Id()),
AutoAssignElasticIps: aws.Bool(d.Get("auto_assign_elastic_ips").(bool)),
AutoAssignPublicIps: aws.Bool(d.Get("auto_assign_public_ips").(bool)),
CustomInstanceProfileArn: aws.String(d.Get("custom_instance_profile_arn").(string)),
CustomRecipes: lt.CustomRecipes(d),
CustomSecurityGroupIds: makeAwsStringSet(d.Get("custom_security_group_ids").(*schema.Set)),
EnableAutoHealing: aws.Bool(d.Get("auto_healing").(bool)),
InstallUpdatesOnBoot: aws.Bool(d.Get("install_updates_on_boot").(bool)),
LifecycleEventConfiguration: lt.LifecycleEventConfiguration(d),
Name: aws.String(d.Get("name").(string)),
Packages: makeAwsStringSet(d.Get("system_packages").(*schema.Set)),
UseEbsOptimizedInstances: aws.Bool(d.Get("use_ebs_optimized_instances").(bool)),
Attributes: lt.AttributeMap(d),
VolumeConfigurations: lt.VolumeConfigurations(d),
}
if lt.CustomShortName {
req.Shortname = aws.String(d.Get("short_name").(string))
} else {
req.Shortname = aws.String(lt.TypeName)
}
log.Printf("[DEBUG] Updating OpsWorks layer: %s", d.Id())
if d.HasChange("elastic_load_balancer") {
lbo, lbn := d.GetChange("elastic_load_balancer")
loadBalancerOld := aws.String(lbo.(string))
loadBalancerNew := aws.String(lbn.(string))
if loadBalancerOld != nil && *loadBalancerOld != "" {
log.Printf("[DEBUG] Dettaching load balancer: %s", *loadBalancerOld)
_, err := client.DetachElasticLoadBalancer(&opsworks.DetachElasticLoadBalancerInput{
ElasticLoadBalancerName: loadBalancerOld,
LayerId: aws.String(d.Id()),
})
if err != nil {
return err
}
}
if loadBalancerNew != nil && *loadBalancerNew != "" {
log.Printf("[DEBUG] Attaching load balancer: %s", *loadBalancerNew)
client.AttachElasticLoadBalancer(&opsworks.AttachElasticLoadBalancerInput{
ElasticLoadBalancerName: loadBalancerNew,
LayerId: aws.String(d.Id()),
})
}
}
_, err := client.UpdateLayer(req)
if err != nil {
return err
}
return lt.Read(d, client)
}