func resourceAwsCustomerGatewayRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn gatewayFilter := &ec2.Filter{ Name: aws.String("customer-gateway-id"), Values: []*string{aws.String(d.Id())}, } resp, err := conn.DescribeCustomerGateways(&ec2.DescribeCustomerGatewaysInput{ Filters: []*ec2.Filter{gatewayFilter}, }) if err != nil { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" { d.SetId("") return nil } else { log.Printf("[ERROR] Error finding CustomerGateway: %s", err) return err } } if len(resp.CustomerGateways) != 1 { return fmt.Errorf("[ERROR] Error finding CustomerGateway: %s", d.Id()) } customerGateway := resp.CustomerGateways[0] d.Set("bgp_asn", customerGateway.BgpAsn) d.Set("ip_address", customerGateway.IpAddress) d.Set("type", customerGateway.Type) d.Set("tags", tagsToMap(customerGateway.Tags)) return nil }
func resourceHerokuAddonRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*heroku.Service) addon, err := resourceHerokuAddonRetrieve( d.Get("app").(string), d.Id(), client) if err != nil { return err } // Determine the plan. If we were configured without a specific plan, // then just avoid the plan altogether (accepting anything that // Heroku sends down). plan := addon.Plan.Name if v := d.Get("plan").(string); v != "" { if idx := strings.IndexRune(v, ':'); idx == -1 { idx = strings.IndexRune(plan, ':') if idx > -1 { plan = plan[:idx] } } } d.Set("name", addon.Name) d.Set("plan", plan) d.Set("provider_id", addon.ProviderID) if err := d.Set("config_vars", addon.ConfigVars); 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 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 }
// resourceArmLocalNetworkGatewayRead goes ahead and reads the state of the corresponding ARM local network gateway. func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error { lnetClient := meta.(*ArmClient).localNetConnClient id, err := parseAzureResourceID(d.Id()) if err != nil { return err } name := id.Path["localNetworkGateways"] resGroup := id.ResourceGroup resp, err := lnetClient.Get(resGroup, name) if err != nil { if resp.StatusCode == http.StatusNotFound { d.SetId("") return nil } return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err) } d.Set("gateway_address", resp.Properties.GatewayIPAddress) prefs := []string{} if ps := *resp.Properties.LocalNetworkAddressSpace.AddressPrefixes; ps != nil { prefs = ps } d.Set("address_space", prefs) return nil }
func resourcePacketSSHKeyRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*packngo.Client) key, _, err := client.SSHKeys.Get(d.Id()) if err != nil { err = friendlyError(err) // If the key is somehow already destroyed, mark as // succesfully gone if isNotFound(err) { d.SetId("") return nil } return err } d.Set("id", key.ID) d.Set("name", key.Label) d.Set("public_key", key.Key) d.Set("fingerprint", key.FingerPrint) d.Set("created", key.Created) d.Set("updated", key.Updated) return nil }
func resourceCloudFlareRecordUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*cloudflare.Client) // CloudFlare requires we send all values for an update request updateRecord := &cloudflare.UpdateRecord{ Name: d.Get("name").(string), Type: d.Get("type").(string), Content: d.Get("value").(string), } if ttl, ok := d.GetOk("ttl"); ok { updateRecord.Ttl = ttl.(string) } if priority, ok := d.GetOk("priority"); ok { updateRecord.Priority = priority.(string) } log.Printf("[DEBUG] CloudFlare Record update configuration: %#v", updateRecord) err := client.UpdateRecord(d.Get("domain").(string), d.Id(), updateRecord) if err != nil { return fmt.Errorf("Failed to update CloudFlare Record: %s", err) } return resourceCloudFlareRecordRead(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 resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn log.Printf("[DEBUG] Security Group destroy: %v", d.Id()) return resource.Retry(5*time.Minute, func() error { _, err := conn.DeleteSecurityGroup(&ec2.DeleteSecurityGroupInput{ GroupId: aws.String(d.Id()), }) if err != nil { ec2err, ok := err.(awserr.Error) if !ok { return err } switch ec2err.Code() { case "InvalidGroup.NotFound": return nil case "DependencyViolation": // If it is a dependency violation, we want to retry return err default: // Any other error, we want to quit the retry loop immediately return resource.RetryError{Err: err} } } return nil }) }
func resourceAwsIamUserPolicyRead(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn user, name := resourceAwsIamUserPolicyParseId(d.Id()) request := &iam.GetUserPolicyInput{ PolicyName: aws.String(name), UserName: aws.String(user), } var err error getResp, err := iamconn.GetUserPolicy(request) if err != nil { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me d.SetId("") return nil } return fmt.Errorf("Error reading IAM policy %s from user %s: %s", name, user, err) } if getResp.PolicyDocument == nil { return fmt.Errorf("GetUserPolicy returned a nil policy document") } policy, err := url.QueryUnescape(*getResp.PolicyDocument) if err != nil { return err } return d.Set("policy", policy) }
func resourceAwsSecurityGroupRead(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 } sg := sgRaw.(*ec2.SecurityGroup) ingressRules := resourceAwsSecurityGroupIPPermGather(d, sg.IpPermissions) egressRules := resourceAwsSecurityGroupIPPermGather(d, sg.IpPermissionsEgress) d.Set("description", sg.Description) d.Set("name", sg.GroupName) d.Set("vpc_id", sg.VpcId) d.Set("owner_id", sg.OwnerId) d.Set("ingress", ingressRules) d.Set("egress", egressRules) d.Set("tags", tagsToMap(sg.Tags)) return nil }
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) }
func resourceLBMonitorV1Read(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) } m, err := monitors.Get(networkingClient, d.Id()).Extract() if err != nil { return CheckDeleted(d, err, "LB monitor") } log.Printf("[DEBUG] Retreived OpenStack LB Monitor %s: %+v", d.Id(), m) d.Set("type", m.Type) d.Set("delay", m.Delay) d.Set("timeout", m.Timeout) d.Set("max_retries", m.MaxRetries) d.Set("tenant_id", m.TenantID) d.Set("url_path", m.URLPath) d.Set("http_method", m.HTTPMethod) d.Set("expected_codes", m.ExpectedCodes) d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp)) return nil }
func resourceDNSimpleRecordCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*dnsimple.Client) // Create the new record newRecord := &dnsimple.ChangeRecord{ Name: d.Get("name").(string), Type: d.Get("type").(string), Value: d.Get("value").(string), } if ttl, ok := d.GetOk("ttl"); ok { newRecord.Ttl = ttl.(string) } log.Printf("[DEBUG] DNSimple Record create configuration: %#v", newRecord) recId, err := client.CreateRecord(d.Get("domain").(string), newRecord) if err != nil { return fmt.Errorf("Failed to create DNSimple Record: %s", err) } d.SetId(recId) log.Printf("[INFO] record ID: %s", d.Id()) return resourceDNSimpleRecordRead(d, meta) }
func resourceDNSimpleRecordUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*dnsimple.Client) updateRecord := &dnsimple.ChangeRecord{} if attr, ok := d.GetOk("name"); ok { updateRecord.Name = attr.(string) } if attr, ok := d.GetOk("type"); ok { updateRecord.Type = attr.(string) } if attr, ok := d.GetOk("value"); ok { updateRecord.Value = attr.(string) } if attr, ok := d.GetOk("ttl"); ok { updateRecord.Ttl = attr.(string) } log.Printf("[DEBUG] DNSimple Record update configuration: %#v", updateRecord) _, err := client.UpdateRecord(d.Get("domain").(string), d.Id(), updateRecord) if err != nil { return fmt.Errorf("Failed to update DNSimple Record: %s", err) } return resourceDNSimpleRecordRead(d, meta) }
func resourceDynRecordDelete(d *schema.ResourceData, meta interface{}) error { mutex.Lock() defer mutex.Unlock() client := meta.(*dynect.ConvenientClient) record := &dynect.Record{ ID: d.Id(), Name: d.Get("name").(string), Zone: d.Get("zone").(string), FQDN: d.Get("fqdn").(string), Type: d.Get("type").(string), } log.Printf("[INFO] Deleting Dyn record: %s, %s", record.FQDN, record.ID) // delete the record err := client.DeleteRecord(record) if err != nil { return fmt.Errorf("Failed to delete Dyn record: %s", err) } // publish the zone err = client.PublishZone(record.Zone) if err != nil { return fmt.Errorf("Failed to publish Dyn zone: %s", err) } return nil }
func resourceAwsMainRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn vpcId := d.Get("vpc_id").(string) routeTableId := d.Get("route_table_id").(string) log.Printf("[INFO] Creating main route table association: %s => %s", vpcId, routeTableId) mainAssociation, err := findMainRouteTableAssociation(conn, vpcId) if err != nil { return err } resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{ AssociationId: mainAssociation.RouteTableAssociationId, RouteTableId: aws.String(routeTableId), }) if err != nil { return err } d.Set("original_route_table_id", mainAssociation.RouteTableId) d.SetId(*resp.NewAssociationId) log.Printf("[INFO] New main route table association ID: %s", d.Id()) return nil }
func resourceDynRecordRead(d *schema.ResourceData, meta interface{}) error { mutex.Lock() defer mutex.Unlock() client := meta.(*dynect.ConvenientClient) record := &dynect.Record{ ID: d.Id(), Name: d.Get("name").(string), Zone: d.Get("zone").(string), TTL: d.Get("ttl").(string), FQDN: d.Get("fqdn").(string), Type: d.Get("type").(string), } err := client.GetRecord(record) if err != nil { return fmt.Errorf("Couldn't find Dyn record: %s", err) } d.Set("zone", record.Zone) d.Set("fqdn", record.FQDN) d.Set("name", record.Name) d.Set("type", record.Type) d.Set("ttl", record.TTL) d.Set("value", record.Value) return nil }
func resourceLBVipV1Read(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) } p, err := vips.Get(networkingClient, d.Id()).Extract() if err != nil { return CheckDeleted(d, err, "LB VIP") } log.Printf("[DEBUG] Retreived OpenStack LB VIP %s: %+v", d.Id(), p) d.Set("name", p.Name) d.Set("subnet_id", p.SubnetID) d.Set("protocol", p.Protocol) d.Set("port", p.ProtocolPort) d.Set("pool_id", p.PoolID) d.Set("port_id", p.PortID) d.Set("tenant_id", p.TenantID) d.Set("address", p.Address) d.Set("description", p.Description) d.Set("conn_limit", p.ConnLimit) d.Set("admin_state_up", p.AdminStateUp) return nil }
func resourceCloudFlareRecordCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*cloudflare.Client) // Create the new record newRecord := &cloudflare.CreateRecord{ Name: d.Get("name").(string), Type: d.Get("type").(string), Content: d.Get("value").(string), } if ttl, ok := d.GetOk("ttl"); ok { newRecord.Ttl = ttl.(string) } if priority, ok := d.GetOk("priority"); ok { newRecord.Priority = priority.(string) } log.Printf("[DEBUG] CloudFlare Record create configuration: %#v", newRecord) rec, err := client.CreateRecord(d.Get("domain").(string), newRecord) if err != nil { return fmt.Errorf("Failed to create CloudFlare Record: %s", err) } d.SetId(rec.Id) log.Printf("[INFO] CloudFlare Record ID: %s", d.Id()) return resourceCloudFlareRecordRead(d, meta) }
func resourceCloudStackDiskDelete(d *schema.ResourceData, meta interface{}) error { cs := meta.(*cloudstack.CloudStackClient) // Detach the volume if err := resourceCloudStackDiskDetach(d, meta); err != nil { return err } // Create a new parameter struct p := cs.Volume.NewDeleteVolumeParams(d.Id()) // Delete the voluem if _, err := cs.Volume.DeleteVolume(p); err != nil { // This is a very poor way to be told the ID does no longer exist :( if strings.Contains(err.Error(), fmt.Sprintf( "Invalid parameter id value=%s due to incorrect long value format, "+ "or entity does not exist", d.Id())) { return nil } return err } return nil }
func resourceMailgunDomainCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*mailgun.Client) opts := mailgun.CreateDomain{} opts.Name = d.Get("name").(string) opts.SmtpPassword = d.Get("smtp_password").(string) opts.SpamAction = d.Get("spam_action").(string) opts.Wildcard = d.Get("wildcard").(bool) log.Printf("[DEBUG] Domain create configuration: %#v", opts) domain, err := client.CreateDomain(&opts) if err != nil { return err } d.SetId(domain) log.Printf("[INFO] Domain ID: %s", d.Id()) // Retrieve and update state of domain _, err = resourceMailginDomainRetrieve(d.Id(), client, d) if err != nil { return err } return nil }
func resourceAwsLBCookieStickinessPolicyDelete(d *schema.ResourceData, meta interface{}) error { elbconn := meta.(*AWSClient).elbconn lbName, _, policyName := resourceAwsLBCookieStickinessPolicyParseId(d.Id()) // Perversely, if we Set an empty list of PolicyNames, we detach the // policies attached to a listener, which is required to delete the // policy itself. setLoadBalancerOpts := &elb.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String(d.Get("load_balancer").(string)), LoadBalancerPort: aws.Int64(int64(d.Get("lb_port").(int))), PolicyNames: []*string{}, } if _, err := elbconn.SetLoadBalancerPoliciesOfListener(setLoadBalancerOpts); err != nil { return fmt.Errorf("Error removing LBCookieStickinessPolicy: %s", err) } request := &elb.DeleteLoadBalancerPolicyInput{ LoadBalancerName: aws.String(lbName), PolicyName: aws.String(policyName), } if _, err := elbconn.DeleteLoadBalancerPolicy(request); err != nil { return fmt.Errorf("Error deleting LB stickiness policy %s: %s", d.Id(), err) } return nil }
func resourceAwsRDSClusterInstanceDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).rdsconn log.Printf("[DEBUG] RDS Cluster Instance destroy: %v", d.Id()) opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())} log.Printf("[DEBUG] RDS Cluster Instance destroy configuration: %s", opts) if _, err := conn.DeleteDBInstance(&opts); err != nil { return err } // re-uses db_instance refresh func log.Println("[INFO] Waiting for RDS Cluster Instance to be destroyed") stateConf := &resource.StateChangeConf{ Pending: []string{"modifying", "deleting"}, Target: "", Refresh: resourceAwsDbInstanceStateRefreshFunc(d, meta), Timeout: 40 * time.Minute, MinTimeout: 10 * time.Second, } if _, err := stateConf.WaitForState(); err != nil { return err } return nil }
func resourceAwsDbParameterGroupDeleteRefreshFunc( d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { rdsconn := meta.(*AWSClient).rdsconn return func() (interface{}, string, error) { deleteOpts := rds.DeleteDBParameterGroupInput{ DBParameterGroupName: aws.String(d.Id()), } if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil { rdserr, ok := err.(awserr.Error) if !ok { return d, "error", err } if rdserr.Code() != "DBParameterGroupNotFoundFault" { return d, "error", err } } return d, "destroyed", nil } }
func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error { addonLock.Lock() defer addonLock.Unlock() client := meta.(*heroku.Service) app := d.Get("app").(string) opts := heroku.AddonCreateOpts{Plan: d.Get("plan").(string)} if v := d.Get("config"); v != nil { config := make(map[string]string) for _, v := range v.([]interface{}) { for k, v := range v.(map[string]interface{}) { config[k] = v.(string) } } opts.Config = &config } log.Printf("[DEBUG] Addon create configuration: %#v, %#v", app, opts) a, err := client.AddonCreate(app, opts) if err != nil { return err } d.SetId(a.ID) log.Printf("[INFO] Addon ID: %s", d.Id()) return resourceHerokuAddonRead(d, meta) }
func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error { rdsconn := meta.(*AWSClient).rdsconn tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{})) createOpts := rds.CreateDBParameterGroupInput{ DBParameterGroupName: aws.String(d.Get("name").(string)), DBParameterGroupFamily: aws.String(d.Get("family").(string)), Description: aws.String(d.Get("description").(string)), Tags: tags, } log.Printf("[DEBUG] Create DB Parameter Group: %#v", createOpts) _, err := rdsconn.CreateDBParameterGroup(&createOpts) if err != nil { return fmt.Errorf("Error creating DB Parameter Group: %s", err) } d.Partial(true) d.SetPartial("name") d.SetPartial("family") d.SetPartial("description") d.Partial(false) d.SetId(*createOpts.DBParameterGroupName) log.Printf("[INFO] DB Parameter Group ID: %s", d.Id()) return resourceAwsDbParameterGroupUpdate(d, meta) }
func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) hchk, err := config.clientCompute.HttpHealthChecks.Get( config.Project, d.Id()).Do() if err != nil { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { // The resource doesn't exist anymore log.Printf("[WARN] Removing HTTP Health Check %q because it's gone", d.Get("name").(string)) d.SetId("") return nil } return fmt.Errorf("Error reading HttpHealthCheck: %s", err) } d.Set("host", hchk.Host) d.Set("request_path", hchk.RequestPath) d.Set("check_interval_sec", hchk.CheckIntervalSec) d.Set("health_threshold", hchk.HealthyThreshold) d.Set("port", hchk.Port) d.Set("timeout_sec", hchk.TimeoutSec) d.Set("unhealthy_threshold", hchk.UnhealthyThreshold) d.Set("self_link", hchk.SelfLink) return nil }
func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Retrieve information about firewall rule: %s", d.Id()) config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } rule, err := rules.Get(networkingClient, d.Id()).Extract() if err != nil { return CheckDeleted(d, err, "FW rule") } d.Set("protocol", rule.Protocol) d.Set("action", rule.Action) d.Set("name", rule.Name) d.Set("description", rule.Description) d.Set("ip_version", rule.IPVersion) d.Set("source_ip_address", rule.SourceIPAddress) d.Set("destination_ip_address", rule.DestinationIPAddress) d.Set("source_port", rule.SourcePort) d.Set("destination_port", rule.DestinationPort) d.Set("enabled", rule.Enabled) return nil }
func resourceAwsDbInstanceRetrieve( d *schema.ResourceData, meta interface{}) (*rds.DBInstance, error) { conn := meta.(*AWSClient).rdsconn opts := rds.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(d.Id()), } log.Printf("[DEBUG] DB Instance describe configuration: %#v", opts) resp, err := conn.DescribeDBInstances(&opts) if err != nil { dbinstanceerr, ok := err.(awserr.Error) if ok && dbinstanceerr.Code() == "DBInstanceNotFound" { return nil, nil } return nil, fmt.Errorf("Error retrieving DB Instances: %s", err) } if len(resp.DBInstances) != 1 || *resp.DBInstances[0].DBInstanceIdentifier != d.Id() { if err != nil { return nil, nil } } return resp.DBInstances[0], nil }
func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error { cs := meta.(*cloudstack.CloudStackClient) // Get the virtual machine details vm, count, err := cs.VirtualMachine.GetVirtualMachineByName(d.Get("virtual_machine").(string)) if err != nil { if count == 0 { log.Printf("[DEBUG] Instance %s does no longer exist", d.Get("virtual_machine").(string)) d.SetId("") return nil } else { return err } } // Read NIC info found := false for _, n := range vm.Nic { if n.Id == d.Id() { d.Set("ipaddress", n.Ipaddress) setValueOrID(d, "network", n.Networkname, n.Networkid) setValueOrID(d, "virtual_machine", vm.Name, vm.Id) found = true break } } if !found { log.Printf("[DEBUG] NIC for network %s does no longer exist", d.Get("network").(string)) d.SetId("") } return nil }