// 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 }
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 }
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) }
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) }
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) }
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) }
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 }
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) }
// 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 }
// 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 }
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) }
// 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 }
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) }
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) }
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) }
func UpdateUser(d *schema.ResourceData, meta interface{}) error { conf := meta.(*providerConfiguration) if d.HasChange("password") { _, newpw := d.GetChange("password") var stmtSQL string /* ALTER USER syntax introduced in MySQL 5.7.6 deprecates SET PASSWORD (GH-8230) */ ver, _ := version.NewVersion("5.7.6") if conf.ServerVersion.LessThan(ver) { stmtSQL = fmt.Sprintf("SET PASSWORD FOR '%s'@'%s' = PASSWORD('%s')", d.Get("user").(string), d.Get("host").(string), newpw.(string)) } else { stmtSQL = fmt.Sprintf("ALTER USER '%s'@'%s' IDENTIFIED BY '%s'", d.Get("user").(string), d.Get("host").(string), newpw.(string)) } log.Println("Executing query:", stmtSQL) _, _, err := conf.Conn.Query(stmtSQL) if err != nil { return err } } return nil }
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) }
func resourceAwsSnsTopicUpdate(d *schema.ResourceData, meta interface{}) error { snsconn := meta.(*AWSClient).snsconn resource := *resourceAwsSnsTopic() for k, _ := range resource.Schema { if attrKey, ok := SNSAttributeMap[k]; ok { if d.HasChange(k) { log.Printf("[DEBUG] Updating %s", attrKey) _, n := d.GetChange(k) // Ignore an empty policy if !(k == "policy" && n == "") { // Make API call to update attributes req := &sns.SetTopicAttributesInput{ TopicArn: aws.String(d.Id()), AttributeName: aws.String(attrKey), AttributeValue: aws.String(n.(string)), } snsconn.SetTopicAttributes(req) } } } } return resourceAwsSnsTopicRead(d, meta) }
func resourceAwsInternetGatewayDetach(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 Internet Gateway '%s' as no VPC ID is set", d.Id()) return nil } log.Printf( "[INFO] Detaching Internet Gateway '%s' from VPC '%s'", d.Id(), vpcID.(string)) // Wait for it to be fully detached before continuing log.Printf("[DEBUG] Waiting for internet gateway (%s) to detach", d.Id()) stateConf := &resource.StateChangeConf{ Pending: []string{"detaching"}, Target: "detached", Refresh: detachIGStateRefreshFunc(conn, d.Id(), vpcID.(string)), Timeout: 5 * time.Minute, Delay: 10 * time.Second, } if _, err := stateConf.WaitForState(); err != nil { return fmt.Errorf( "Error waiting for internet gateway (%s) to detach: %s", d.Id(), err) } return nil }
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.Long(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", awsutil.StringValue(service)) return resourceAwsEcsServiceRead(d, meta) }
// 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 }
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) }
// 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 from %s", remove, d.Id()) _, err := conn.DeleteTags(&ec2.DeleteTagsInput{ Resources: []*string{aws.String(d.Id())}, Tags: remove, }) if err != nil { return err } } if len(create) > 0 { log.Printf("[DEBUG] Creating tags: %s for %s", awsutil.StringValue(create), d.Id()) _, err := conn.CreateTags(&ec2.CreateTagsInput{ Resources: []*string{aws.String(d.Id())}, Tags: create, }) if err != nil { return err } } } return nil }
func resourceAwsIamUserUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("name") || d.HasChange("path") { iamconn := meta.(*AWSClient).iamconn on, nn := d.GetChange("name") _, np := d.GetChange("path") request := &iam.UpdateUserInput{ UserName: aws.String(on.(string)), NewUserName: aws.String(nn.(string)), NewPath: aws.String(np.(string)), } log.Println("[DEBUG] Update IAM User request:", request) _, err := iamconn.UpdateUser(request) if err != nil { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { log.Printf("[WARN] No IAM user by name (%s) found", d.Id()) d.SetId("") return nil } return fmt.Errorf("Error updating IAM User %s: %s", d.Id(), err) } return resourceAwsIamUserRead(d, meta) } return nil }
func instanceProfileSetRoles(d *schema.ResourceData, iamconn *iam.IAM) error { oldInterface, newInterface := d.GetChange("roles") oldRoles := oldInterface.(*schema.Set) newRoles := newInterface.(*schema.Set) currentRoles := schema.CopySet(oldRoles) d.Partial(true) for _, role := range oldRoles.Difference(newRoles).List() { err := instanceProfileRemoveRole(iamconn, d.Id(), role.(string)) if err != nil { return fmt.Errorf("Error removing role %s from IAM instance profile %s: %s", role, d.Id(), err) } currentRoles.Remove(role) d.Set("roles", currentRoles) d.SetPartial("roles") } for _, role := range newRoles.Difference(oldRoles).List() { err := instanceProfileAddRole(iamconn, d.Id(), role.(string)) if err != nil { return fmt.Errorf("Error adding role %s to IAM instance profile %s: %s", role, d.Id(), err) } currentRoles.Add(role) d.Set("roles", currentRoles) d.SetPartial("roles") } d.Partial(false) return nil }
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) }
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) }
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) }
// setTags is a helper to set the tags for a resource. It expects the // tags field to be named "tags" func setTagsR53(conn *route53.Route53, d *schema.ResourceData, resourceType string) error { if d.HasChange("tags") { oraw, nraw := d.GetChange("tags") o := oraw.(map[string]interface{}) n := nraw.(map[string]interface{}) create, remove := diffTagsR53(tagsFromMapR53(o), tagsFromMapR53(n)) // Set tags r := make([]*string, len(remove)) for i, t := range remove { r[i] = t.Key } log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:%#v", create, remove) req := &route53.ChangeTagsForResourceInput{ ResourceID: aws.String(d.Id()), ResourceType: aws.String(resourceType), } if len(create) > 0 { req.AddTags = create } if len(r) > 0 { req.RemoveTagKeys = r } _, err := conn.ChangeTagsForResource(req) if err != nil { return err } } return nil }
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(®isterInstancesOpts) 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) }