<commit_before>package opc

import (
	"fmt"

	"github.com/hashicorp/go-oracle-terraform/compute"
	"github.com/hashicorp/terraform/helper/schema"
)

func resourceOPCIPAddressAssociation() *schema.Resource {
	return &schema.Resource{
		Create: resourceOPCIPAddressAssociationCreate,
		Read:   resourceOPCIPAddressAssociationRead,
		Update: resourceOPCIPAddressAssociationUpdate,
		Delete: resourceOPCIPAddressAssociationDelete,
		Importer: &schema.ResourceImporter{
			State: schema.ImportStatePassthrough,
		},

		Schema: map[string]*schema.Schema{
			"name": {
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"ip_address_reservation": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"vnic": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"description": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"tags": tagsOptionalSchema(),
			"uri": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	}
}

func resourceOPCIPAddressAssociationCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*compute.Client).IPAddressAssociations()

	input := compute.CreateIPAddressAssociationInput{
		Name: d.Get("name").(string),
	}

	if ipAddressReservation, ok := d.GetOk("ip_address_reservation"); ok {
		input.IPAddressReservation = ipAddressReservation.(string)
	}

	if vnic, ok := d.GetOk("vnic"); ok {
		input.Vnic = vnic.(string)
	}

	tags := getStringList(d, "tags")
	if len(tags) != 0 {
		input.Tags = tags
	}

	if description, ok := d.GetOk("description"); ok {
		input.Description = description.(string)
	}

	info, err := client.CreateIPAddressAssociation(&input)
	if err != nil {
		return fmt.Errorf("Error creating IP Address Association: %s", err)
	}

	d.SetId(info.Name)
	return resourceOPCIPAddressAssociationRead(d, meta)
}

func resourceOPCIPAddressAssociationRead(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*compute.Client).IPAddressAssociations()
	name := d.Id()

	getInput := compute.GetIPAddressAssociationInput{
		name,
	}
	result, err := client.GetIPAddressAssociation(&getInput)
	if err != nil {
		// IP Address Association does not exist
		if compute.WasNotFoundError(err) {
			d.SetId("")
			return nil
		}
		return fmt.Errorf("Error reading IP Address Association %s: %s", name, err)<commit_msg>refactor the read<commit_after>package opc

import (
	"fmt"

	"github.com/hashicorp/go-oracle-terraform/compute"
	"github.com/hashicorp/terraform/helper/schema"
)

func resourceOPCIPAddressAssociation() *schema.Resource {
	return &schema.Resource{
		Create: resourceOPCIPAddressAssociationCreate,
		Read:   resourceOPCIPAddressAssociationRead,
		Update: resourceOPCIPAddressAssociationUpdate,
		Delete: resourceOPCIPAddressAssociationDelete,
		Importer: &schema.ResourceImporter{
			State: schema.ImportStatePassthrough,
		},

		Schema: map[string]*schema.Schema{
			"name": {
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"ip_address_reservation": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"vnic": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"description": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"tags": tagsOptionalSchema(),
			"uri": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	}
}

func resourceOPCIPAddressAssociationCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*compute.Client).IPAddressAssociations()

	input := compute.CreateIPAddressAssociationInput{
		Name: d.Get("name").(string),
	}

	if ipAddressReservation, ok := d.GetOk("ip_address_reservation"); ok {
		input.IPAddressReservation = ipAddressReservation.(string)
	}

	if vnic, ok := d.GetOk("vnic"); ok {
		input.Vnic = vnic.(string)
	}

	tags := getStringList(d, "tags")
	if len(tags) != 0 {
		input.Tags = tags
	}

	if description, ok := d.GetOk("description"); ok {
		input.Description = description.(string)
	}

	info, err := client.CreateIPAddressAssociation(&input)
	if err != nil {
		return fmt.Errorf("Error creating IP Address Association: %s", err)
	}

	d.SetId(info.Name)
	return resourceOPCIPAddressAssociationRead(d, meta)
}

func resourceOPCIPAddressAssociationRead(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*compute.Client).IPAddressAssociations()
	name := d.Id()

	getInput := compute.GetIPAddressAssociationInput{
		Name: name,
	}
	result, err := client.GetIPAddressAssociation(&getInput)
	if err != nil {
		// IP Address Association does not exist
		if compute.WasNotFoundError(err) {
			d.SetId("")
			return nil
		}
		return fmt.Errorf("Error reading IP Address Association %s: %s", name, err)
{'fraction_non_alphanumeric': 0.12935429056924383, 'fraction_numerical': 0.0004248088360237893, 'mean_word_length': 4.232222222222222, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6812717', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1512, 'n_words': 308}