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 } } if arn, err := buildRDSsubgrpARN(d, meta); err == nil { if err := setTagsRDS(conn, d, arn); err != nil { return err } else { d.SetPartial("tags") } } return resourceAwsDbSubnetGroupRead(d, meta) }
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 }
// 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 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) }
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) }
func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).redshiftconn 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.ModifyClusterSubnetGroup(&redshift.ModifyClusterSubnetGroupInput{ ClusterSubnetGroupName: aws.String(d.Id()), SubnetIds: sIds, }) if err != nil { return err } } return nil }
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), }) } return err } return resourceAwsCloudWatchLogGroupRead(d, meta) }
// resourceAzureAffinityGroupUpdate does all the necessary API calls to // update the state of the affinity group on Azure. func resourceAzureAffinityGroupUpdate(d *schema.ResourceData, meta interface{}) error { affinityGroupClient := meta.(*Client).affinityGroupClient name := d.Get("name").(string) clabel := d.HasChange("label") cdesc := d.HasChange("description") if clabel || cdesc { log.Println("[INFO] Beginning Affinity Group update process.") params := affinitygroup.UpdateAffinityGroupParams{} if clabel { params.Label = d.Get("label").(string) } if cdesc { params.Description = d.Get("description").(string) } log.Println("[INFO] Sending Affinity Group update request to Azure.") err := affinityGroupClient.UpdateAffinityGroup(name, params) if err != nil { return fmt.Errorf("Error updating Azure Affinity Group parameters: %s", err) } } return nil }
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 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) }
func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error { cs := meta.(*cloudstack.CloudStackClient) // Check if the name or display text is changed if d.HasChange("name") || d.HasChange("display_text") { // Create a new parameter struct p := cs.VPC.NewUpdateVPCParams(d.Id()) // Set the display text displaytext, ok := d.GetOk("display_text") if !ok { displaytext = d.Get("name") } // Set the (new) display text p.SetDisplaytext(displaytext.(string)) // Update the VPC _, err := cs.VPC.UpdateVPC(p) if err != nil { return fmt.Errorf( "Error updating VPC %s: %s", d.Get("name").(string), err) } } return resourceCloudStackVPCRead(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 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) }
func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) region := getOptionalRegion(d, config) d.Partial(true) if d.HasChange("target") { target_name := d.Get("target").(string) target_ref := &compute.TargetReference{Target: target_name} op, err := config.clientCompute.ForwardingRules.SetTarget( config.Project, region, d.Id(), target_ref).Do() if err != nil { return fmt.Errorf("Error updating target: %s", err) } err = computeOperationWaitRegion(config, op, region, "Updating Forwarding Rule") if err != nil { return err } d.SetPartial("target") } d.Partial(false) return resourceComputeForwardingRuleRead(d, meta) }
// 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 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) }
func resourceAwsEcrRepositoryPolicyUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ecrconn if !d.HasChange("policy") { return nil } input := ecr.SetRepositoryPolicyInput{ RepositoryName: aws.String(d.Get("repository").(string)), RegistryId: aws.String(d.Get("registry_id").(string)), PolicyText: aws.String(d.Get("policy").(string)), } out, err := conn.SetRepositoryPolicy(&input) if err != nil { return err } repositoryPolicy := *out d.SetId(*repositoryPolicy.RepositoryName) d.Set("registry_id", *repositoryPolicy.RegistryId) return nil }
// 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", create, d.Id()) _, err := conn.CreateTags(&ec2.CreateTagsInput{ Resources: []*string{aws.String(d.Id())}, Tags: create, }) if err != nil { return err } } } return nil }
func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts routers.UpdateOpts if d.HasChange("name") { updateOpts.Name = d.Get("name").(string) } if d.HasChange("admin_state_up") { asu := d.Get("admin_state_up").(bool) updateOpts.AdminStateUp = &asu } log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts) _, err = routers.Update(networkingClient, d.Id(), updateOpts).Extract() if err != nil { return fmt.Errorf("Error updating OpenStack Neutron Router: %s", err) } return resourceNetworkingRouterV2Read(d, meta) }
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 resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) objectStorageClient, err := config.objectStorageV1Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack object storage client: %s", err) } updateOpts := containers.UpdateOpts{ ContainerRead: d.Get("container_read").(string), ContainerSyncTo: d.Get("container_sync_to").(string), ContainerSyncKey: d.Get("container_sync_key").(string), ContainerWrite: d.Get("container_write").(string), ContentType: d.Get("content_type").(string), } if d.HasChange("metadata") { updateOpts.Metadata = resourceContainerMetadataV2(d) } _, err = containers.Update(objectStorageClient, d.Id(), updateOpts).Extract() if err != nil { return fmt.Errorf("Error updating OpenStack container: %s", err) } return resourceObjectStorageContainerV1Read(d, meta) }
func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) computeClient, err := config.computeV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack compute client: %s", err) } updateOpts := secgroups.UpdateOpts{ Name: d.Get("name").(string), Description: d.Get("description").(string), } log.Printf("[DEBUG] Updating Security Group (%s) with options: %+v", d.Id(), updateOpts) _, err = secgroups.Update(computeClient, d.Id(), updateOpts).Extract() if err != nil { return fmt.Errorf("Error updating OpenStack security group (%s): %s", d.Id(), err) } if d.HasChange("rule") { oldSGRaw, newSGRaw := d.GetChange("rule") oldSGRSet, newSGRSet := oldSGRaw.(*schema.Set), newSGRaw.(*schema.Set) secgrouprulesToAdd := newSGRSet.Difference(oldSGRSet) secgrouprulesToRemove := oldSGRSet.Difference(newSGRSet) log.Printf("[DEBUG] Security group rules to add: %v", secgrouprulesToAdd) log.Printf("[DEBUG] Security groups rules to remove: %v", secgrouprulesToRemove) for _, rawRule := range secgrouprulesToAdd.List() { createRuleOpts := resourceSecGroupRuleCreateOptsV2(d, rawRule) rule, err := secgroups.CreateRule(computeClient, createRuleOpts).Extract() if err != nil { return fmt.Errorf("Error adding rule to OpenStack security group (%s): %s", d.Id(), err) } log.Printf("[DEBUG] Added rule (%s) to OpenStack security group (%s) ", rule.ID, d.Id()) } for _, r := range secgrouprulesToRemove.List() { rule := resourceSecGroupRuleV2(d, r) err := secgroups.DeleteRule(computeClient, rule.ID).ExtractErr() if err != nil { errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError) if !ok { return fmt.Errorf("Error removing rule (%s) from OpenStack security group (%s): %s", rule.ID, d.Id(), err) } if errCode.Actual == 404 { continue } else { return fmt.Errorf("Error removing rule (%s) from OpenStack security group (%s)", rule.ID, d.Id()) } } else { log.Printf("[DEBUG] Removed rule (%s) from OpenStack security group (%s): %s", rule.ID, d.Id(), err) } } } return resourceComputeSecGroupV2Read(d, meta) }
func resourceAwsIamInstanceProfileUpdate(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn if !d.HasChange("roles") { return nil } return instanceProfileSetRoles(d, iamconn) }
func resourceAwsProxyProtocolPolicyUpdate(d *schema.ResourceData, meta interface{}) error { elbconn := meta.(*AWSClient).elbconn elbname := aws.String(d.Get("load_balancer").(string)) // Retrieve the current ELB policies for updating the state req := &elb.DescribeLoadBalancersInput{ LoadBalancerNames: []*string{elbname}, } resp, err := elbconn.DescribeLoadBalancers(req) if err != nil { if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil } return fmt.Errorf("Error retrieving ELB attributes: %s", err) } backends := flattenBackendPolicies(resp.LoadBalancerDescriptions[0].BackendServerDescriptions) _, policyName := resourceAwsProxyProtocolPolicyParseId(d.Id()) d.Partial(true) if d.HasChange("instance_ports") { o, n := d.GetChange("instance_ports") os := o.(*schema.Set) ns := n.(*schema.Set) remove := os.Difference(ns).List() add := ns.Difference(os).List() inputs := []*elb.SetLoadBalancerPoliciesForBackendServerInput{} i, err := resourceAwsProxyProtocolPolicyRemove(policyName, remove, backends) if err != nil { return err } inputs = append(inputs, i...) i, err = resourceAwsProxyProtocolPolicyAdd(policyName, add, backends) if err != nil { return err } inputs = append(inputs, i...) for _, input := range inputs { input.LoadBalancerName = elbname if _, err := elbconn.SetLoadBalancerPoliciesForBackendServer(input); err != nil { return fmt.Errorf("Error setting policy for backend: %s", err) } } d.SetPartial("instance_ports") } return resourceAwsProxyProtocolPolicyRead(d, meta) }
// resourceAzureLocalNetworkConnectionUpdate does all the necessary API calls // update the settings of our Local Network on Azure. func resourceAzureLocalNetworkConnectionUpdate(d *schema.ResourceData, meta interface{}) error { azureClient := meta.(*Client) mgmtClient := azureClient.mgmtClient vnetClient := azureClient.vnetClient log.Println("[INFO] Fetching current network configuration from Azure.") azureClient.vnetMutex.Lock() defer azureClient.vnetMutex.Unlock() netConf, err := vnetClient.GetVirtualNetworkConfiguration() if err != nil { return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) } name := d.Get("name").(string) cvpn := d.HasChange("vpn_gateway_address") cprefixes := d.HasChange("address_space_prefixes") var found bool for i, lnet := range netConf.Configuration.LocalNetworkSites { if lnet.Name == name { found = true if cvpn { netConf.Configuration.LocalNetworkSites[i].VPNGatewayAddress = d.Get("vpn_gateway_address").(string) } if cprefixes { var prefixes []string for _, prefix := range d.Get("address_space_prefixes").([]interface{}) { prefixes = append(prefixes, prefix.(string)) } netConf.Configuration.LocalNetworkSites[i].AddressSpace.AddressPrefix = prefixes } break } } // remove the resource from the state of it has been deleted in the meantime: if !found { log.Println(fmt.Printf("[INFO] Azure local network '%s' has been deleted remotely. Removimg from Terraform.", name)) d.SetId("") } else if cvpn || cprefixes { // else, send the configuration back to Azure: log.Println("[INFO] Sending updated network configuration back to Azure.") reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf) if err != nil { return fmt.Errorf("Failed setting updated network configuration: %s", err) } err = mgmtClient.WaitForOperation(reqID, nil) if err != nil { return fmt.Errorf("Failed updating the network configuration: %s", err) } } return nil }
// resourceArmStorageAccountUpdate is unusual in the ARM API where most resources have a combined // and idempotent operation for CreateOrUpdate. In particular updating all of the parameters // available requires a call to Update per parameter... func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).storageServiceClient id, err := parseAzureResourceID(d.Id()) if err != nil { return err } storageAccountName := id.Path["storageAccounts"] resourceGroupName := id.ResourceGroup d.Partial(true) if d.HasChange("account_type") { accountType := d.Get("account_type").(string) opts := storage.AccountUpdateParameters{ Properties: &storage.AccountPropertiesUpdateParameters{ AccountType: storage.AccountType(accountType), }, } accResp, err := client.Update(resourceGroupName, storageAccountName, opts) if err != nil { return fmt.Errorf("Error updating Azure Storage Account type %q: %s", storageAccountName, err) } _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response.Response, http.StatusOK) if err != nil { return fmt.Errorf("Error updating Azure Storage Account type %q: %s", storageAccountName, err) } d.SetPartial("account_type") } if d.HasChange("tags") { tags := d.Get("tags").(map[string]interface{}) opts := storage.AccountUpdateParameters{ Tags: expandTags(tags), } accResp, err := client.Update(resourceGroupName, storageAccountName, opts) if err != nil { return fmt.Errorf("Error updating Azure Storage Account tags %q: %s", storageAccountName, err) } _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response.Response, http.StatusOK) if err != nil { return fmt.Errorf("Error updating Azure Storage Account tags %q: %s", storageAccountName, err) } d.SetPartial("tags") } d.Partial(false) return nil }
// resourceAzureDnsServerUpdate does all the necessary API calls // to update the DNS definition on Azure. func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) error { azureClient := meta.(*Client) mgmtClient := azureClient.mgmtClient vnetClient := azureClient.vnetClient var found bool name := d.Get("name").(string) if d.HasChange("dns_address") { log.Println("[DEBUG] DNS server address has changes; updating it on Azure.") log.Println("[INFO] Fetching current network configuration from Azure.") azureClient.vnetMutex.Lock() defer azureClient.vnetMutex.Unlock() netConf, err := vnetClient.GetVirtualNetworkConfiguration() if err != nil { return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) } // search for our DNS and update its address value: for i, dns := range netConf.Configuration.DNS.DNSServers { if dns.Name == name { found = true netConf.Configuration.DNS.DNSServers[i].IPAddress = d.Get("dns_address").(string) break } } // if the config has changes, send the configuration back to Azure: if found { log.Println("[INFO] Sending updated network configuration back to Azure.") reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf) if err != nil { return fmt.Errorf("Failed issuing update to network configuration: %s", err) } err = mgmtClient.WaitForOperation(reqID, nil) if err != nil { return fmt.Errorf("Error setting network configuration: %s", err) } return nil } } // remove the resource from the state if it has been deleted in the meantime: if !found { d.SetId("") } return nil }
func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{}) error { rdsconn := meta.(*AWSClient).rdsconn d.Partial(true) if d.HasChange("parameter") { o, n := d.GetChange("parameter") if o == nil { o = new(schema.Set) } if n == nil { n = new(schema.Set) } os := o.(*schema.Set) ns := n.(*schema.Set) // Expand the "parameter" set to aws-sdk-go compat []rds.Parameter parameters, err := expandParameters(ns.Difference(os).List()) if err != nil { return err } if len(parameters) > 0 { modifyOpts := rds.ModifyDBParameterGroupInput{ DBParameterGroupName: aws.String(d.Get("name").(string)), Parameters: parameters, } log.Printf("[DEBUG] Modify DB Parameter Group: %s", modifyOpts) _, err = rdsconn.ModifyDBParameterGroup(&modifyOpts) if err != nil { return fmt.Errorf("Error modifying DB Parameter Group: %s", err) } } d.SetPartial("parameter") } if arn, err := buildRDSPGARN(d, meta); err == nil { if err := setTagsRDS(rdsconn, d, arn); err != nil { return err } else { d.SetPartial("tags") } } d.Partial(false) return resourceAwsDbParameterGroupRead(d, meta) }
func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) sb := &storage.Bucket{} if d.HasChange("website") { if v, ok := d.GetOk("website"); ok { websites := v.([]interface{}) if len(websites) > 1 { return fmt.Errorf("At most one website block is allowed") } // Setting fields to "" to be explicit that the PATCH call will // delete this field. if len(websites) == 0 { sb.Website.NotFoundPage = "" sb.Website.MainPageSuffix = "" } else { website := websites[0].(map[string]interface{}) sb.Website = &storage.BucketWebsite{} if v, ok := website["not_found_page"]; ok { sb.Website.NotFoundPage = v.(string) } else { sb.Website.NotFoundPage = "" } if v, ok := website["main_page_suffix"]; ok { sb.Website.MainPageSuffix = v.(string) } else { sb.Website.MainPageSuffix = "" } } } } res, err := config.clientStorage.Buckets.Patch(d.Get("name").(string), sb).Do() if err != nil { return err } log.Printf("[DEBUG] Patched bucket %v at location %v\n\n", res.Name, res.SelfLink) // Assign the bucket ID as the resource ID d.Set("self_link", res.SelfLink) d.SetId(res.Id) return nil }
func UpdatePublicKey(d *schema.ResourceData, meta interface{}) error { client := meta.(*rundeck.Client) if d.HasChange("key_material") { path := d.Get("path").(string) keyMaterial := d.Get("key_material").(string) err := client.ReplacePublicKey(path, keyMaterial) if err != nil { return err } } return ReadPublicKey(d, meta) }