本文整理匯總了Golang中github.com/xanzy/terraform-api/helper/schema.ResourceData.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.Get方法的具體用法?Golang ResourceData.Get怎麽用?Golang ResourceData.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/xanzy/terraform-api/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.Get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resourceDNSimpleRecordUpdate
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)
}
示例2: resourceAzureAffinityGroupRead
// resourceAzureAffinityGroupRead does all the necessary API calls to
// read the state of the affinity group off Azure.
func resourceAzureAffinityGroupRead(d *schema.ResourceData, meta interface{}) error {
affinityGroupClient := meta.(*Client).affinityGroupClient
log.Println("[INFO] Issuing Azure Affinity Group list request.")
affinityGroups, err := affinityGroupClient.ListAffinityGroups()
if err != nil {
return fmt.Errorf("Error obtaining Affinity Group list off Azure: %s", err)
}
var found bool
name := d.Get("name").(string)
for _, group := range affinityGroups.AffinityGroups {
if group.Name == name {
found = true
d.Set("location", group.Location)
d.Set("label", group.Label)
d.Set("description", group.Description)
break
}
}
if !found {
// it means the affinity group has been deleted in the meantime, so we
// must stop tracking it:
d.SetId("")
}
return nil
}
示例3: resourceHerokuAddonRead
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
}
示例4: setTagsS3
// 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
}
示例5: resourceContainerMetadataV2
func resourceContainerMetadataV2(d *schema.ResourceData) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("metadata").(map[string]interface{}) {
m[key] = val.(string)
}
return m
}
示例6: resourceAzureLocalNetworkConnectionRead
// resourceAzureLocalNetworkConnectionRead does all the necessary API calls to
// read the state of our local natwork from Azure.
func resourceAzureLocalNetworkConnectionRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client)
vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.")
netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
}
var found bool
name := d.Get("name").(string)
// browsing for our network config:
for _, lnet := range netConf.Configuration.LocalNetworkSites {
if lnet.Name == name {
found = true
d.Set("vpn_gateway_address", lnet.VPNGatewayAddress)
d.Set("address_space_prefixes", lnet.AddressSpace.AddressPrefix)
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("")
}
return nil
}
示例7: resourceFWRuleV1Read
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
}
示例8: resourceSqlDatabaseDelete
func resourceSqlDatabaseDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
database_name := d.Get("name").(string)
instance_name := d.Get("instance").(string)
project := config.Project
op, err := config.clientSqlAdmin.Databases.Delete(project, instance_name,
database_name).Do()
if err != nil {
return fmt.Errorf("Error, failed to delete"+
"database %s in instance %s: %s", database_name,
instance_name, err)
}
err = sqladminOperationWait(config, op, "Delete Database")
if err != nil {
return fmt.Errorf("Error, failure waiting for deletion of %s "+
"in %s: %s", database_name, instance_name, err)
}
return nil
}
示例9: resourceAwsSecurityGroupUpdate
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)
}
示例10: resourceAwsIamPolicyAttachmentCreate
func resourceAwsIamPolicyAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).iamconn
name := d.Get("name").(string)
arn := d.Get("policy_arn").(string)
users := expandStringList(d.Get("users").(*schema.Set).List())
roles := expandStringList(d.Get("roles").(*schema.Set).List())
groups := expandStringList(d.Get("groups").(*schema.Set).List())
if len(users) == 0 && len(roles) == 0 && len(groups) == 0 {
return fmt.Errorf("[WARN] No Users, Roles, or Groups specified for IAM Policy Attachment %s", name)
} else {
var userErr, roleErr, groupErr error
if users != nil {
userErr = attachPolicyToUsers(conn, users, arn)
}
if roles != nil {
roleErr = attachPolicyToRoles(conn, roles, arn)
}
if groups != nil {
groupErr = attachPolicyToGroups(conn, groups, arn)
}
if userErr != nil || roleErr != nil || groupErr != nil {
return composeErrors(fmt.Sprint("[WARN] Error attaching policy with IAM Policy Attachment ", name, ":"), userErr, roleErr, groupErr)
}
}
d.SetId(d.Get("name").(string))
return resourceAwsIamPolicyAttachmentRead(d, meta)
}
示例11: resourceSqlDatabaseCreate
func resourceSqlDatabaseCreate(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 := &sqladmin.Database{
Name: database_name,
Instance: instance_name,
}
op, err := config.clientSqlAdmin.Databases.Insert(project, instance_name,
db).Do()
if err != nil {
return fmt.Errorf("Error, failed to insert "+
"database %s into instance %s: %s", database_name,
instance_name, err)
}
err = sqladminOperationWait(config, op, "Insert Database")
if err != nil {
return fmt.Errorf("Error, failure waiting for insertion of %s "+
"into %s: %s", database_name, instance_name, err)
}
return resourceSqlDatabaseRead(d, meta)
}
示例12: resourceLBMonitorV1Read
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
}
示例13: resourceAwsProxyProtocolPolicyRead
func resourceAwsProxyProtocolPolicyRead(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)
ports := []*string{}
for ip := range backends {
ipstr := strconv.Itoa(int(ip))
ports = append(ports, &ipstr)
}
d.Set("instance_ports", ports)
d.Set("load_balancer", *elbname)
return nil
}
示例14: resourceAwsProxyProtocolPolicyCreate
func resourceAwsProxyProtocolPolicyCreate(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbconn
elbname := aws.String(d.Get("load_balancer").(string))
input := &elb.CreateLoadBalancerPolicyInput{
LoadBalancerName: elbname,
PolicyAttributes: []*elb.PolicyAttribute{
&elb.PolicyAttribute{
AttributeName: aws.String("ProxyProtocol"),
AttributeValue: aws.String("True"),
},
},
PolicyName: aws.String("TFEnableProxyProtocol"),
PolicyTypeName: aws.String("ProxyProtocolPolicyType"),
}
// Create a policy
log.Printf("[DEBUG] ELB create a policy %s from policy type %s",
*input.PolicyName, *input.PolicyTypeName)
if _, err := elbconn.CreateLoadBalancerPolicy(input); err != nil {
return fmt.Errorf("Error creating a policy %s: %s",
*input.PolicyName, err)
}
// Assign the policy name for use later
d.Partial(true)
d.SetId(fmt.Sprintf("%s:%s", *elbname, *input.PolicyName))
d.SetPartial("load_balancer")
log.Printf("[INFO] ELB PolicyName: %s", *input.PolicyName)
return resourceAwsProxyProtocolPolicyUpdate(d, meta)
}
示例15: resourceAwsKinesisStreamRead
func resourceAwsKinesisStreamRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).kinesisconn
sn := d.Get("name").(string)
state, err := readKinesisStreamState(conn, sn)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "ResourceNotFoundException" {
d.SetId("")
return nil
}
return fmt.Errorf("[WARN] Error reading Kinesis Stream: \"%s\", code: \"%s\"", awsErr.Message(), awsErr.Code())
}
return err
}
d.Set("arn", state.arn)
d.Set("shard_count", state.shardCount)
// set tags
describeTagsOpts := &kinesis.ListTagsForStreamInput{
StreamName: aws.String(sn),
}
tagsResp, err := conn.ListTagsForStream(describeTagsOpts)
if err != nil {
log.Printf("[DEBUG] Error retrieving tags for Stream: %s. %s", sn, err)
} else {
d.Set("tags", tagsToMapKinesis(tagsResp.Tags))
}
return nil
}