当前位置: 首页>>代码示例>>Golang>>正文


Golang terraform.ResourceState类代码示例

本文整理汇总了Golang中github.com/hashicorp/terraform/terraform.ResourceState的典型用法代码示例。如果您正苦于以下问题:Golang ResourceState类的具体用法?Golang ResourceState怎么用?Golang ResourceState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ResourceState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: resource_heroku_addon_update

func resource_heroku_addon_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client
	rs := s.MergeDiff(d)

	app := rs.Attributes["app"]

	if attr, ok := d.Attributes["plan"]; ok {
		ad, err := client.AddonUpdate(
			app, rs.ID,
			attr.New)

		if err != nil {
			return s, err
		}

		// Store the new ID
		rs.ID = ad.Id
	}

	addon, err := resource_heroku_addon_retrieve(app, rs.ID, client)

	if err != nil {
		return rs, err
	}

	return resource_heroku_addon_update_state(rs, addon)
}
开发者ID:JasonGiedymin,项目名称:terraform,代码行数:31,代码来源:resource_heroku_addon.go

示例2: resource_digitalocean_domain_create

func resource_digitalocean_domain_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client
	// Merge the diff into the state so that we have all the attributes
	// properly.
	rs := s.MergeDiff(d)

	// Build up our creation options
	opts := digitalocean.CreateDomain{
		Name:      rs.Attributes["name"],
		IPAddress: rs.Attributes["ip_address"],
	}

	log.Printf("[DEBUG] Domain create configuration: %#v", opts)

	name, err := client.CreateDomain(&opts)
	if err != nil {
		return nil, fmt.Errorf("Error creating Domain: %s", err)
	}

	rs.ID = name
	log.Printf("[INFO] Domain Name: %s", name)

	return rs, nil
}
开发者ID:GeorgeErickson,项目名称:terraform-1,代码行数:28,代码来源:resource_digitalocean_domain.go

示例3: Apply

func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
	c *terraform.ResourceConfig) error {
	// Ensure the connection type is SSH
	if err := helper.VerifySSH(s); err != nil {
		return err
	}

	// Get the SSH configuration
	conf, err := helper.ParseSSHConfig(s)
	if err != nil {
		return err
	}

	// Collect the scripts
	scripts, err := p.collectScripts(c)
	if err != nil {
		return err
	}
	for _, s := range scripts {
		defer s.Close()
	}

	// Copy and execute each script
	if err := p.runScripts(conf, scripts); err != nil {
		return err
	}
	return nil
}
开发者ID:kyriakosoikonomakos,项目名称:terraform,代码行数:28,代码来源:resource_provisioner.go

示例4: resource_digitalocean_record_update

func resource_digitalocean_record_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client
	rs := s.MergeDiff(d)

	updateRecord := digitalocean.UpdateRecord{}

	if attr, ok := d.Attributes["name"]; ok {
		updateRecord.Name = attr.New
	}

	log.Printf("[DEBUG] record update configuration: %#v", updateRecord)

	err := client.UpdateRecord(rs.Attributes["domain"], rs.ID, &updateRecord)
	if err != nil {
		return rs, fmt.Errorf("Failed to update record: %s", err)
	}

	record, err := resource_digitalocean_record_retrieve(rs.Attributes["domain"], rs.ID, client)
	if err != nil {
		return rs, fmt.Errorf("Couldn't find record: %s", err)
	}

	return resource_digitalocean_record_update_state(rs, record)
}
开发者ID:GeorgeErickson,项目名称:terraform-1,代码行数:28,代码来源:resource_digitalocean_record.go

示例5: resource_aws_route_table_association_update

func resource_aws_route_table_association_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	ec2conn := p.ec2conn

	rs := s.MergeDiff(d)
	log.Printf(
		"[INFO] Replacing route table association: %s => %s",
		rs.Attributes["subnet_id"],
		rs.Attributes["route_table_id"])
	resp, err := ec2conn.ReassociateRouteTable(
		rs.ID,
		rs.Attributes["route_table_id"])
	if err != nil {
		ec2err, ok := err.(*ec2.Error)
		if ok && ec2err.Code == "InvalidAssociationID.NotFound" {
			// Not found, so just create a new one
			return resource_aws_route_table_association_create(s, d, meta)
		}

		return s, err
	}

	// Update the ID
	rs.ID = resp.AssociationId
	log.Printf("[INFO] Association ID: %s", rs.ID)

	rs.Dependencies = []terraform.ResourceDependency{
		terraform.ResourceDependency{ID: rs.Attributes["route_table_id"]},
	}

	return rs, nil
}
开发者ID:EZTABLE,项目名称:terraform,代码行数:35,代码来源:resource_aws_route_table_association.go

示例6: resource_aws_s3_bucket_create

func resource_aws_s3_bucket_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	s3conn := p.s3conn

	// Merge the diff into the state so that we have all the attributes
	// properly.
	rs := s.MergeDiff(d)

	// Get the bucket and optional acl
	bucket := rs.Attributes["bucket"]
	acl := "private"
	if other, ok := rs.Attributes["acl"]; ok {
		acl = other
	}

	log.Printf("[DEBUG] S3 bucket create: %s, ACL: %s", bucket, acl)
	s3Bucket := s3conn.Bucket(bucket)
	err := s3Bucket.PutBucket(s3.ACL(acl))
	if err != nil {
		return nil, fmt.Errorf("Error creating S3 bucket: %s", err)
	}

	// Assign the bucket name as the resource ID
	rs.ID = bucket
	return rs, nil
}
开发者ID:EZTABLE,项目名称:terraform,代码行数:29,代码来源:resource_aws_s3_bucket.go

示例7: resource_cloudflare_record_update

func resource_cloudflare_record_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client
	rs := s.MergeDiff(d)

	// Cloudflare requires we send all values
	// for an update request, so we just
	// merge out diff and send the current
	// state of affairs to them
	updateRecord := cloudflare.UpdateRecord{
		Name:     rs.Attributes["name"],
		Content:  rs.Attributes["value"],
		Type:     rs.Attributes["type"],
		Ttl:      rs.Attributes["ttl"],
		Priority: rs.Attributes["priority"],
	}

	log.Printf("[DEBUG] record update configuration: %#v", updateRecord)

	err := client.UpdateRecord(rs.Attributes["domain"], rs.ID, &updateRecord)
	if err != nil {
		return rs, fmt.Errorf("Failed to update record: %s", err)
	}

	record, err := resource_cloudflare_record_retrieve(rs.Attributes["domain"], rs.ID, client)
	if err != nil {
		return rs, fmt.Errorf("Couldn't find record: %s", err)
	}

	return resource_cloudflare_record_update_state(rs, record)
}
开发者ID:GeorgeErickson,项目名称:terraform-1,代码行数:34,代码来源:resource_cloudflare_record.go

示例8: resource_aws_route_table_association_create

func resource_aws_route_table_association_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	ec2conn := p.ec2conn
	rs := s.MergeDiff(d)

	log.Printf(
		"[INFO] Creating route table association: %s => %s",
		rs.Attributes["subnet_id"],
		rs.Attributes["route_table_id"])
	resp, err := ec2conn.AssociateRouteTable(
		rs.Attributes["route_table_id"],
		rs.Attributes["subnet_id"])
	if err != nil {
		return nil, err
	}

	// Set the ID and return
	rs.ID = resp.AssociationId
	log.Printf("[INFO] Association ID: %s", rs.ID)

	rs.Dependencies = []terraform.ResourceDependency{
		terraform.ResourceDependency{ID: rs.Attributes["route_table_id"]},
	}

	return rs, nil
}
开发者ID:EZTABLE,项目名称:terraform,代码行数:29,代码来源:resource_aws_route_table_association.go

示例9: resource_aws_subnet_create

func resource_aws_subnet_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	ec2conn := p.ec2conn

	// Merge the diff so that we have all the proper attributes
	s = s.MergeDiff(d)

	// Create the Subnet
	createOpts := &ec2.CreateSubnet{
		AvailabilityZone: s.Attributes["availability_zone"],
		CidrBlock:        s.Attributes["cidr_block"],
		VpcId:            s.Attributes["vpc_id"],
	}
	log.Printf("[DEBUG] Subnet create config: %#v", createOpts)
	resp, err := ec2conn.CreateSubnet(createOpts)
	if err != nil {
		return nil, fmt.Errorf("Error creating subnet: %s", err)
	}

	// Get the ID and store it
	subnet := &resp.Subnet
	s.ID = subnet.SubnetId
	log.Printf("[INFO] Subnet ID: %s", s.ID)

	// Wait for the Subnet to become available
	log.Printf(
		"[DEBUG] Waiting for subnet (%s) to become available",
		s.ID)
	stateConf := &resource.StateChangeConf{
		Pending: []string{"pending"},
		Target:  "available",
		Refresh: SubnetStateRefreshFunc(ec2conn, s.ID),
		Timeout: 10 * time.Minute,
	}
	subnetRaw, err := stateConf.WaitForState()
	if err != nil {
		return s, fmt.Errorf(
			"Error waiting for subnet (%s) to become available: %s",
			s.ID, err)
	}

	// Map public ip on launch must be set in another API call
	if attr := s.Attributes["map_public_ip_on_launch"]; attr == "true" {
		modifyOpts := &ec2.ModifySubnetAttribute{
			SubnetId:            s.ID,
			MapPublicIpOnLaunch: true,
		}
		log.Printf("[DEBUG] Subnet modify attributes: %#v", modifyOpts)
		_, err := ec2conn.ModifySubnetAttribute(modifyOpts)
		if err != nil {
			return nil, fmt.Errorf("Error modify subnet attributes: %s", err)
		}
	}

	// Update our attributes and return
	return resource_aws_subnet_update_state(s, subnetRaw.(*ec2.Subnet))
}
开发者ID:apriendeau,项目名称:terraform,代码行数:60,代码来源:resource_aws_subnet.go

示例10: resource_aws_instance_update

func resource_aws_instance_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	ec2conn := p.ec2conn
	rs := s.MergeDiff(d)

	modify := false
	opts := new(ec2.ModifyInstance)

	if attr, ok := d.Attributes["source_dest_check"]; ok {
		modify = true
		opts.SourceDestCheck = attr.New != "" && attr.New != "false"
		opts.SetSourceDestCheck = true
		rs.Attributes["source_dest_check"] = strconv.FormatBool(
			opts.SourceDestCheck)
	}

	if modify {
		log.Printf("[INFO] Modifing instance %s: %#v", s.ID, opts)
		if _, err := ec2conn.ModifyInstance(s.ID, opts); err != nil {
			return s, err
		}

		// TODO(mitchellh): wait for the attributes we modified to
		// persist the change...
	}

	return rs, nil
}
开发者ID:JasonGiedymin,项目名称:terraform,代码行数:31,代码来源:resource_aws_instance.go

示例11: resource_heroku_drain_create

func resource_heroku_drain_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client

	// Merge the diff into the state so that we have all the attributes
	// properly.
	rs := s.MergeDiff(d)

	app := rs.Attributes["app"]
	url := rs.Attributes["url"]

	log.Printf("[DEBUG] Drain create configuration: %#v, %#v", app, url)

	dr, err := client.LogDrainCreate(app, url)

	if err != nil {
		return s, err
	}

	rs.ID = dr.Id
	rs.Attributes["url"] = dr.URL
	rs.Attributes["token"] = dr.Token

	log.Printf("[INFO] Drain ID: %s", rs.ID)

	return rs, nil
}
开发者ID:JasonGiedymin,项目名称:terraform,代码行数:30,代码来源:resource_heroku_drain.go

示例12: resource_aws_internet_gateway_update

func resource_aws_internet_gateway_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	ec2conn := p.ec2conn

	// Merge the diff so we have the latest attributes
	rs := s.MergeDiff(d)

	// A note on the states below: the AWS docs (as of July, 2014) say
	// that the states would be: attached, attaching, detached, detaching,
	// but when running, I noticed that the state is usually "available" when
	// it is attached.

	// If we're already attached, detach it first
	if err := resource_aws_internet_gateway_detach(ec2conn, s); err != nil {
		return s, err
	}

	// Set the VPC ID to empty since we're detached at this point
	delete(rs.Attributes, "vpc_id")

	if attr, ok := d.Attributes["vpc_id"]; ok && attr.New != "" {
		err := resource_aws_internet_gateway_attach(ec2conn, s, attr.New)
		if err != nil {
			return rs, err
		}

		rs.Attributes["vpc_id"] = attr.New
	}

	return resource_aws_internet_gateway_update_state(rs, nil)
}
开发者ID:GeorgeErickson,项目名称:terraform-1,代码行数:34,代码来源:resource_aws_internet_gateway.go

示例13: resource_heroku_domain_create

func resource_heroku_domain_create(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	client := p.client

	// Merge the diff into the state so that we have all the attributes
	// properly.
	rs := s.MergeDiff(d)

	app := rs.Attributes["app"]
	hostname := rs.Attributes["hostname"]

	log.Printf("[DEBUG] Domain create configuration: %#v, %#v", app, hostname)

	do, err := client.DomainCreate(app, hostname)

	if err != nil {
		return s, err
	}

	rs.ID = do.Id
	rs.Attributes["hostname"] = do.Hostname
	rs.Attributes["cname"] = fmt.Sprintf("%s.herokuapp.com", app)

	log.Printf("[INFO] Domain ID: %s", rs.ID)

	return rs, nil
}
开发者ID:JasonGiedymin,项目名称:terraform,代码行数:30,代码来源:resource_heroku_domain.go

示例14: resource_aws_security_group_update_state

func resource_aws_security_group_update_state(
	s *terraform.ResourceState,
	sg *ec2.SecurityGroupInfo) (*terraform.ResourceState, error) {

	s.Attributes["description"] = sg.Description
	s.Attributes["name"] = sg.Name
	s.Attributes["vpc_id"] = sg.VpcId
	s.Attributes["owner_id"] = sg.OwnerId

	// Flatten our ingress values
	toFlatten := make(map[string]interface{})
	toFlatten["ingress"] = flattenIPPerms(sg.IPPerms)

	for k, v := range flatmap.Flatten(toFlatten) {
		s.Attributes[k] = v
	}

	s.Dependencies = nil
	if s.Attributes["vpc_id"] != "" {
		s.Dependencies = append(s.Dependencies,
			terraform.ResourceDependency{ID: s.Attributes["vpc_id"]},
		)
	}

	return s, nil
}
开发者ID:routelastresort,项目名称:terraform,代码行数:26,代码来源:resource_aws_security_group.go

示例15: resource_openstack_compute_update

func resource_openstack_compute_update(
	s *terraform.ResourceState,
	d *terraform.ResourceDiff,
	meta interface{}) (*terraform.ResourceState, error) {

	p := meta.(*ResourceProvider)
	client := p.client

	// Merge the diff into the state so that we have all the attributes
	// properly.
	rs := s.MergeDiff(d)

	serversApi, err := gophercloud.ServersApi(client.AccessProvider, gophercloud.ApiCriteria{
		Name:      "nova",
		UrlChoice: gophercloud.PublicURL,
	})
	if err != nil {
		return nil, err
	}

	if attr, ok := d.Attributes["name"]; ok {
		_, err := serversApi.UpdateServer(rs.ID, gophercloud.NewServerSettings{
			Name: attr.New,
		})

		if err != nil {
			return nil, err
		}

		rs.Attributes["name"] = attr.New
	}

	if attr, ok := d.Attributes["flavor_ref"]; ok {
		err := serversApi.ResizeServer(rs.Attributes["id"], rs.Attributes["name"], attr.New, "")

		if err != nil {
			return nil, err
		}

		stateConf := &resource.StateChangeConf{
			Pending:    []string{"ACTIVE"},
			Target:     "VERIFY_RESIZE",
			Refresh:    WaitForServerState(serversApi, rs.Attributes["id"]),
			Timeout:    10 * time.Minute,
			Delay:      10 * time.Second,
			MinTimeout: 3 * time.Second,
		}

		_, err = stateConf.WaitForState()

		if err != nil {
			return nil, err
		}

		err = serversApi.ConfirmResize(rs.Attributes["id"])
	}

	return rs, nil
}
开发者ID:haklop,项目名称:terraform,代码行数:59,代码来源:resource_openstack_compute.go


注:本文中的github.com/hashicorp/terraform/terraform.ResourceState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。