本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.Set方法的具體用法?Golang ResourceData.Set怎麽用?Golang ResourceData.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.Set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resourceAwsIamAccessKeyCreate
func resourceAwsIamAccessKeyCreate(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn
request := &iam.CreateAccessKeyInput{
UserName: aws.String(d.Get("user").(string)),
}
createResp, err := iamconn.CreateAccessKey(request)
if err != nil {
return fmt.Errorf(
"Error creating access key for user %s: %s",
*request.UserName,
err,
)
}
if err := d.Set("secret", createResp.AccessKey.SecretAccessKey); err != nil {
return err
}
return resourceAwsIamAccessKeyReadResult(d, &iam.AccessKeyMetadata{
AccessKeyID: createResp.AccessKey.AccessKeyID,
CreateDate: createResp.AccessKey.CreateDate,
Status: createResp.AccessKey.Status,
UserName: createResp.AccessKey.UserName,
})
}
示例2: resourceAwsS3BucketObjectRead
func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) error {
s3conn := meta.(*AWSClient).s3conn
bucket := d.Get("bucket").(string)
key := d.Get("key").(string)
etag := d.Get("etag").(string)
resp, err := s3conn.HeadObject(
&s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
IfMatch: aws.String(etag),
})
if err != nil {
// If S3 returns a 404 Request Failure, mark the object as destroyed
if awsErr, ok := err.(awserr.RequestFailure); ok && awsErr.StatusCode() == 404 {
d.SetId("")
log.Printf("[WARN] Error Reading Object (%s), object not found (HTTP status 404)", key)
return nil
}
return err
}
d.Set("cache_control", resp.CacheControl)
d.Set("content_disposition", resp.ContentDisposition)
d.Set("content_encoding", resp.ContentEncoding)
d.Set("content_language", resp.ContentLanguage)
d.Set("content_type", resp.ContentType)
d.Set("version_id", resp.VersionId)
log.Printf("[DEBUG] Reading S3 Bucket Object meta: %s", resp)
return nil
}
示例3: getVolumeAttachments
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) error {
var attachments []volumeattach.VolumeAttachment
err := volumeattach.List(computeClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
actual, err := volumeattach.ExtractVolumeAttachments(page)
if err != nil {
return false, err
}
attachments = actual
return true, nil
})
if err != nil {
return err
}
vols := make([]map[string]interface{}, len(attachments))
for i, attachment := range attachments {
vols[i] = make(map[string]interface{})
vols[i]["id"] = attachment.ID
vols[i]["volume_id"] = attachment.VolumeID
vols[i]["device"] = attachment.Device
}
log.Printf("[INFO] Volume attachments: %v", vols)
d.Set("volume", vols)
return nil
}
示例4: resourceGithubRepositoryCollaboratorRead
func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Organization).client
u := d.Get("username").(string)
r := d.Get("repository").(string)
isCollaborator, _, err := client.Repositories.IsCollaborator(meta.(*Organization).name, r, u)
if !isCollaborator || err != nil {
d.SetId("")
return nil
}
collaborators, _, err := client.Repositories.ListCollaborators(meta.(*Organization).name, r,
&github.ListOptions{})
if err != nil {
return err
}
for _, c := range collaborators {
if *c.Login == u {
permName, err := getRepoPermission(c.Permissions)
if err != nil {
return err
}
d.Set("permission", permName)
return nil
}
}
return nil
}
示例5: resourceAwsSnsTopicRead
func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
snsconn := meta.(*AWSClient).snsconn
attributeOutput, err := snsconn.GetTopicAttributes(&sns.GetTopicAttributesInput{
TopicArn: aws.String(d.Id()),
})
if err != nil {
return err
}
if attributeOutput.Attributes != nil && len(attributeOutput.Attributes) > 0 {
attrmap := attributeOutput.Attributes
resource := *resourceAwsSnsTopic()
// iKey = internal struct key, oKey = AWS Attribute Map key
for iKey, oKey := range SNSAttributeMap {
log.Printf("[DEBUG] Updating %s => %s", iKey, oKey)
if attrmap[oKey] != nil {
// Some of the fetched attributes are stateful properties such as
// the number of subscriptions, the owner, etc. skip those
if resource.Schema[iKey] != nil {
value := *attrmap[oKey]
log.Printf("[DEBUG] Updating %s => %s -> %s", iKey, oKey, value)
d.Set(iKey, *attrmap[oKey])
}
}
}
}
return nil
}
示例6: resourceFirewallRulesRead
func resourceFirewallRulesRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil {
return fmt.Errorf("Error finding edge gateway: %#v", err)
}
ruleList := d.Get("rule").([]interface{})
firewallRules := *edgeGateway.EdgeGateway.Configuration.EdgeGatewayServiceConfiguration.FirewallService
rulesCount := d.Get("rule.#").(int)
for i := 0; i < rulesCount; i++ {
prefix := fmt.Sprintf("rule.%d", i)
if d.Get(prefix+".id").(string) == "" {
log.Printf("[INFO] Rule %d has no id. Searching...", i)
ruleid, err := matchFirewallRule(d, prefix, firewallRules.FirewallRule)
if err == nil {
currentRule := ruleList[i].(map[string]interface{})
currentRule["id"] = ruleid
ruleList[i] = currentRule
}
}
}
d.Set("rule", ruleList)
d.Set("default_action", firewallRules.DefaultAction)
return nil
}
示例7: resourceAwsKeyPairRead
func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
req := &ec2.DescribeKeyPairsInput{
KeyNames: []*string{aws.String(d.Id())},
}
resp, err := conn.DescribeKeyPairs(req)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "InvalidKeyPair.NotFound" {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving KeyPair: %s", err)
}
for _, keyPair := range resp.KeyPairs {
if *keyPair.KeyName == d.Id() {
d.Set("key_name", keyPair.KeyName)
d.Set("fingerprint", keyPair.KeyFingerprint)
return nil
}
}
return fmt.Errorf("Unable to find key pair within: %#v", resp.KeyPairs)
}
示例8: resourceComputeTargetPoolRead
func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region, err := getRegion(d, config)
if err != nil {
return err
}
project, err := getProject(d, config)
if err != nil {
return err
}
tpool, err := config.clientCompute.TargetPools.Get(
project, region, d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Target Pool %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading TargetPool: %s", err)
}
d.Set("self_link", tpool.SelfLink)
return nil
}
示例9: resourceSqlDatabaseRead
func resourceSqlDatabaseRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
database_name := d.Get("name").(string)
instance_name := d.Get("instance").(string)
project := config.Project
db, err := config.clientSqlAdmin.Databases.Get(project, instance_name,
database_name).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing SQL Database %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error, failed to get"+
"database %s in instance %s: %s", database_name,
instance_name, err)
}
d.Set("self_link", db.SelfLink)
d.SetId(instance_name + ":" + database_name)
return nil
}
示例10: resourceComputeRouteRead
func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
route, err := config.clientCompute.Routes.Get(
project, d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Route %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading route: %#v", err)
}
d.Set("next_hop_network", route.NextHopNetwork)
d.Set("self_link", route.SelfLink)
return nil
}
示例11: resourceComputeSslCertificateRead
func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
cert, err := config.clientCompute.SslCertificates.Get(
project, d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing SSL Certificate %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading ssl certificate: %s", err)
}
d.Set("self_link", cert.SelfLink)
d.Set("id", strconv.FormatUint(cert.Id, 10))
return nil
}
示例12: resourceArmAvailabilitySetRead
func resourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) error {
availSetClient := meta.(*ArmClient).availSetClient
id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resGroup := id.ResourceGroup
name := id.Path["availabilitySets"]
resp, err := availSetClient.Get(resGroup, name)
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Error making Read request on Azure Availability Set %s: %s", name, err)
}
availSet := *resp.Properties
d.Set("platform_update_domain_count", availSet.PlatformUpdateDomainCount)
d.Set("platform_fault_domain_count", availSet.PlatformFaultDomainCount)
flattenAndSetTags(d, resp.Tags)
return nil
}
示例13: resourceAwsElasticacheSecurityGroupRead
func resourceAwsElasticacheSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticacheconn
req := &elasticache.DescribeCacheSecurityGroupsInput{
CacheSecurityGroupName: aws.String(d.Get("name").(string)),
}
res, err := conn.DescribeCacheSecurityGroups(req)
if err != nil {
return err
}
if len(res.CacheSecurityGroups) == 0 {
return fmt.Errorf("Error missing %v", d.Get("name"))
}
var group *elasticache.CacheSecurityGroup
for _, g := range res.CacheSecurityGroups {
log.Printf("[DEBUG] CacheSecurityGroupName: %v, id: %v", g.CacheSecurityGroupName, d.Id())
if *g.CacheSecurityGroupName == d.Id() {
group = g
}
}
if group == nil {
return fmt.Errorf("Error retrieving cache security group: %v", res)
}
d.Set("name", group.CacheSecurityGroupName)
d.Set("description", group.Description)
return nil
}
示例14: resourcePagerDutyServiceIntegrationRead
func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*pagerduty.Client)
log.Printf("[INFO] Reading PagerDuty service integration %s", d.Id())
service := d.Get("service").(string)
o := &pagerduty.GetIntegrationOptions{}
serviceIntegration, err := client.GetIntegration(service, d.Id(), *o)
if err != nil {
if isNotFound(err) {
d.SetId("")
return nil
}
return err
}
d.Set("name", serviceIntegration.Name)
d.Set("type", serviceIntegration.Type)
d.Set("service", serviceIntegration.Service)
d.Set("vendor", serviceIntegration.Vendor)
d.Set("integration_key", serviceIntegration.IntegrationKey)
d.Set("integration_email", serviceIntegration.IntegrationEmail)
return nil
}
示例15: resourceAwsVpnGatewayAttachmentRead
func resourceAwsVpnGatewayAttachmentRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
vgwId := d.Get("vpn_gateway_id").(string)
resp, err := conn.DescribeVpnGateways(&ec2.DescribeVpnGatewaysInput{
VpnGatewayIds: []*string{aws.String(vgwId)},
})
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "InvalidVPNGatewayID.NotFound" {
log.Printf("[WARN] VPN Gateway %q not found.", vgwId)
d.SetId("")
return nil
}
return err
}
vgw := resp.VpnGateways[0]
if *vgw.State == "deleted" {
log.Printf("[INFO] VPN Gateway %q appears to have been deleted.", vgwId)
d.SetId("")
return nil
}
vga := vpnGatewayGetAttachment(vgw)
if len(vgw.VpcAttachments) == 0 || *vga.State == "detached" {
d.Set("vpc_id", "")
return nil
}
d.Set("vpc_id", *vga.VpcId)
return nil
}