本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.HasChange方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.HasChange方法的具體用法?Golang ResourceData.HasChange怎麽用?Golang ResourceData.HasChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.HasChange方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UpdateRepository
func UpdateRepository(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)
d.Partial(true)
if d.HasChange("name") {
// Renaming has its own special operation.
err := RenameRepository(d, meta)
if err != nil {
return err
}
d.SetPartial("name")
}
req := &RepositoryWrap{
Repository: Repository{
Title: d.Get("title").(string),
ColorLabel: d.Get("color_label").(string),
DefaultGitBranch: d.Get("default_git_branch").(string),
},
}
err := client.Put([]string{"repositories", d.Id()}, req, nil)
if err != nil {
return err
}
d.Partial(false)
return ReadRepository(d, meta)
}
示例2: resourceAwsDbSubnetGroupUpdate
func resourceAwsDbSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
if d.HasChange("subnet_ids") || d.HasChange("description") {
_, n := d.GetChange("subnet_ids")
if n == nil {
n = new(schema.Set)
}
ns := n.(*schema.Set)
var sIds []*string
for _, s := range ns.List() {
sIds = append(sIds, aws.String(s.(string)))
}
_, err := conn.ModifyDBSubnetGroup(&rds.ModifyDBSubnetGroupInput{
DBSubnetGroupName: aws.String(d.Id()),
DBSubnetGroupDescription: aws.String(d.Get("description").(string)),
SubnetIds: sIds,
})
if err != nil {
return err
}
}
if arn, err := buildRDSsubgrpARN(d.Id(), meta.(*AWSClient).accountid, meta.(*AWSClient).region); err == nil {
if err := setTagsRDS(conn, d, arn); err != nil {
return err
} else {
d.SetPartial("tags")
}
}
return resourceAwsDbSubnetGroupRead(d, meta)
}
示例3: resourceAwsApiGatewayMethodUpdate
func resourceAwsApiGatewayMethodUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Reading API Gateway Method %s", d.Id())
operations := make([]*apigateway.PatchOperation, 0)
if d.HasChange("resource_id") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/resourceId"),
Value: aws.String(d.Get("resource_id").(string)),
})
}
if d.HasChange("request_models") {
operations = append(operations, expandApiGatewayRequestResponseModelOperations(d, "request_models", "requestModels")...)
}
method, err := conn.UpdateMethod(&apigateway.UpdateMethodInput{
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)),
PatchOperations: operations,
})
if err != nil {
return err
}
log.Printf("[DEBUG] Received API Gateway Method: %s", method)
return resourceAwsApiGatewayMethodRead(d, meta)
}
示例4: resourceDigitalOceanFloatingIpUpdate
func resourceDigitalOceanFloatingIpUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client)
if d.HasChange("droplet_id") {
if v, ok := d.GetOk("droplet_id"); ok {
log.Printf("[INFO] Assigning the Floating IP %s to the Droplet %d", d.Id(), 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)
}
} else {
log.Printf("[INFO] Unassigning the Floating IP %s", d.Id())
action, _, err := client.FloatingIPActions.Unassign(d.Id())
if err != nil {
return fmt.Errorf(
"Error Unassigning FloatingIP (%s): %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 Unassigned: %s", d.Id(), unassignedErr)
}
}
}
return resourceDigitalOceanFloatingIpRead(d, meta)
}
示例5: resourceAwsCloudWatchLogGroupUpdate
func resourceAwsCloudWatchLogGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).cloudwatchlogsconn
name := d.Get("name").(string)
log.Printf("[DEBUG] Updating CloudWatch Log Group: %q", name)
if d.HasChange("retention_in_days") {
var err error
if v, ok := d.GetOk("retention_in_days"); ok {
input := cloudwatchlogs.PutRetentionPolicyInput{
LogGroupName: aws.String(name),
RetentionInDays: aws.Int64(int64(v.(int))),
}
log.Printf("[DEBUG] Setting retention for CloudWatch Log Group: %q: %s", name, input)
_, err = conn.PutRetentionPolicy(&input)
} else {
log.Printf("[DEBUG] Deleting retention for CloudWatch Log Group: %q", name)
_, err = conn.DeleteRetentionPolicy(&cloudwatchlogs.DeleteRetentionPolicyInput{
LogGroupName: aws.String(name),
})
}
if err != nil {
return err
}
}
return resourceAwsCloudWatchLogGroupRead(d, meta)
}
示例6: 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))
}
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)
}
示例7: resourceComputeTargetHttpProxyUpdate
func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
d.Partial(true)
if d.HasChange("url_map") {
url_map := d.Get("url_map").(string)
url_map_ref := &compute.UrlMapReference{UrlMap: url_map}
op, err := config.clientCompute.TargetHttpProxies.SetUrlMap(
config.Project, d.Id(), url_map_ref).Do()
if err != nil {
return fmt.Errorf("Error updating target: %s", err)
}
err = computeOperationWaitGlobal(config, op, "Updating Target Http Proxy")
if err != nil {
return err
}
d.SetPartial("url_map")
}
d.Partial(false)
return resourceComputeTargetHttpProxyRead(d, meta)
}
示例8: 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
}
示例9: setAutoscalingTags
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tag"
func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) error {
if d.HasChange("tag") {
oraw, nraw := d.GetChange("tag")
o := setToMapByKey(oraw.(*schema.Set), "key")
n := setToMapByKey(nraw.(*schema.Set), "key")
resourceID := d.Get("name").(string)
c, r := diffAutoscalingTags(
autoscalingTagsFromMap(o, resourceID),
autoscalingTagsFromMap(n, resourceID),
resourceID)
create := autoscaling.CreateOrUpdateTagsInput{
Tags: c,
}
remove := autoscaling.DeleteTagsInput{
Tags: r,
}
// Set tags
if len(r) > 0 {
log.Printf("[DEBUG] Removing autoscaling tags: %#v", r)
if _, err := conn.DeleteTags(&remove); err != nil {
return err
}
}
if len(c) > 0 {
log.Printf("[DEBUG] Creating autoscaling tags: %#v", c)
if _, err := conn.CreateOrUpdateTags(&create); err != nil {
return err
}
}
}
return nil
}
示例10: resourceAwsIamGroupMembershipUpdate
func resourceAwsIamGroupMembershipUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).iamconn
if d.HasChange("users") {
group := d.Get("group").(string)
o, n := d.GetChange("users")
if o == nil {
o = new(schema.Set)
}
if n == nil {
n = new(schema.Set)
}
os := o.(*schema.Set)
ns := n.(*schema.Set)
remove := expandStringList(os.Difference(ns).List())
add := expandStringList(ns.Difference(os).List())
if err := removeUsersFromGroup(conn, remove, group); err != nil {
return err
}
if err := addUsersToGroup(conn, add, group); err != nil {
return err
}
}
return resourceAwsIamGroupMembershipRead(d, meta)
}
示例11: 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)
}
示例12: 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)
}
示例13: resourceAwsDbSubnetGroupUpdate
func resourceAwsDbSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
if d.HasChange("subnet_ids") {
_, n := d.GetChange("subnet_ids")
if n == nil {
n = new(schema.Set)
}
ns := n.(*schema.Set)
var sIds []*string
for _, s := range ns.List() {
sIds = append(sIds, aws.String(s.(string)))
}
_, err := conn.ModifyDBSubnetGroup(&rds.ModifyDBSubnetGroupInput{
DBSubnetGroupName: aws.String(d.Id()),
SubnetIds: sIds,
})
if err != nil {
return err
}
}
return resourceAwsDbSubnetGroupRead(d, meta)
}
示例14: UpdatePolicy
func UpdatePolicy(d *schema.ResourceData, meta interface{}) error {
rmqc := meta.(*rabbithole.Client)
policyId := strings.Split(d.Id(), "@")
if len(policyId) < 2 {
return fmt.Errorf("Unable to determine policy ID")
}
user := policyId[0]
vhost := policyId[1]
if d.HasChange("policy") {
_, newPolicy := d.GetChange("policy")
policyList := newPolicy.([]interface{})
policyMap, ok := policyList[0].(map[string]interface{})
if !ok {
return fmt.Errorf("Unable to parse policy")
}
if err := putPolicy(rmqc, user, vhost, policyMap); err != nil {
return err
}
}
return ReadPolicy(d, meta)
}
示例15: resourceAwsApiGatewayMethodResponseUpdate
func resourceAwsApiGatewayMethodResponseUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Updating API Gateway Method Response %s", d.Id())
operations := make([]*apigateway.PatchOperation, 0)
if d.HasChange("response_models") {
operations = append(operations, expandApiGatewayRequestResponseModelOperations(d, "response_models", "responseModels")...)
}
if d.HasChange("response_parameters_in_json") {
ops, err := expandApiGatewayMethodResponseParametersJSONOperations(d, "response_parameters_in_json", "responseParameters")
if err != nil {
return err
}
operations = append(operations, ops...)
}
out, err := conn.UpdateMethodResponse(&apigateway.UpdateMethodResponseInput{
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)),
StatusCode: aws.String(d.Get("status_code").(string)),
PatchOperations: operations,
})
if err != nil {
return err
}
log.Printf("[DEBUG] Received API Gateway Method Response: %s", out)
return resourceAwsApiGatewayMethodResponseRead(d, meta)
}