mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Add import support for org, folder, billing logging sinks (#1860)
Fixes #1494. * Add import support for `google_logging_organization_sink`, `google_logging_folder_sink`, `google_logging_billing_account_sink`. Using `StateFunc` over `DiffSuppressFunc` should only affect tests; for some reason `TestAccLoggingFolderSink_folderAcceptsFullFolderPath` expected a `folder` value of `folders/{{id}}` vs expecting `{{id}}` when only `DiffSuppressFunc` was used, when in real use `DiffSuppressFunc` should be sufficient.
This commit is contained in:
parent
7911cab2e4
commit
035a581b9f
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// loggingSinkResourceTypes contains all the possible Stackdriver Logging resource types. Used to parse ids safely.
|
// loggingSinkResourceTypes contains all the possible Stackdriver Logging resource types. Used to parse ids safely.
|
||||||
var loggingSinkResourceTypes = []string{
|
var loggingSinkResourceTypes = []string{
|
||||||
"billingAccount",
|
"billingAccounts",
|
||||||
"folders",
|
"folders",
|
||||||
"organizations",
|
"organizations",
|
||||||
"projects",
|
"projects",
|
||||||
|
|
|
@ -12,6 +12,9 @@ func resourceLoggingBillingAccountSink() *schema.Resource {
|
||||||
Delete: resourceLoggingBillingAccountSinkDelete,
|
Delete: resourceLoggingBillingAccountSinkDelete,
|
||||||
Update: resourceLoggingBillingAccountSinkUpdate,
|
Update: resourceLoggingBillingAccountSinkUpdate,
|
||||||
Schema: resourceLoggingSinkSchema(),
|
Schema: resourceLoggingSinkSchema(),
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceLoggingSinkImportState("billing_account"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["billing_account"] = &schema.Schema{
|
schm.Schema["billing_account"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -30,6 +30,10 @@ func TestAccLoggingBillingAccountSink_basic(t *testing.T) {
|
||||||
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.basic", &sink),
|
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.basic", &sink),
|
||||||
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.basic"),
|
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.basic"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_billing_account_sink.basic",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -62,6 +66,10 @@ func TestAccLoggingBillingAccountSink_update(t *testing.T) {
|
||||||
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.update", &sinkAfter),
|
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.update", &sinkAfter),
|
||||||
testAccCheckLoggingBillingAccountSink(&sinkAfter, "google_logging_billing_account_sink.update"),
|
testAccCheckLoggingBillingAccountSink(&sinkAfter, "google_logging_billing_account_sink.update"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_billing_account_sink.update",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -96,6 +104,10 @@ func TestAccLoggingBillingAccountSink_heredoc(t *testing.T) {
|
||||||
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.heredoc", &sink),
|
testAccCheckLoggingBillingAccountSinkExists("google_logging_billing_account_sink.heredoc", &sink),
|
||||||
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.heredoc"),
|
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.heredoc"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_billing_account_sink.heredoc",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -13,12 +14,17 @@ func resourceLoggingFolderSink() *schema.Resource {
|
||||||
Delete: resourceLoggingFolderSinkDelete,
|
Delete: resourceLoggingFolderSinkDelete,
|
||||||
Update: resourceLoggingFolderSinkUpdate,
|
Update: resourceLoggingFolderSinkUpdate,
|
||||||
Schema: resourceLoggingSinkSchema(),
|
Schema: resourceLoggingSinkSchema(),
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceLoggingSinkImportState("folder"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["folder"] = &schema.Schema{
|
schm.Schema["folder"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DiffSuppressFunc: optionalPrefixSuppress("folders/"),
|
StateFunc: func(v interface{}) string {
|
||||||
|
return strings.Replace(v.(string), "folders/", "", 1)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["include_children"] = &schema.Schema{
|
schm.Schema["include_children"] = &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
|
|
|
@ -32,6 +32,10 @@ func TestAccLoggingFolderSink_basic(t *testing.T) {
|
||||||
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sink),
|
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sink),
|
||||||
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.basic"),
|
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.basic"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_folder_sink.basic",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -58,6 +62,10 @@ func TestAccLoggingFolderSink_folderAcceptsFullFolderPath(t *testing.T) {
|
||||||
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sink),
|
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sink),
|
||||||
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.basic"),
|
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.basic"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_folder_sink.basic",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -92,6 +100,10 @@ func TestAccLoggingFolderSink_update(t *testing.T) {
|
||||||
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sinkAfter),
|
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.basic", &sinkAfter),
|
||||||
testAccCheckLoggingFolderSink(&sinkAfter, "google_logging_folder_sink.basic"),
|
testAccCheckLoggingFolderSink(&sinkAfter, "google_logging_folder_sink.basic"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_folder_sink.basic",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -127,6 +139,10 @@ func TestAccLoggingFolderSink_heredoc(t *testing.T) {
|
||||||
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.heredoc", &sink),
|
testAccCheckLoggingFolderSinkExists("google_logging_folder_sink.heredoc", &sink),
|
||||||
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.heredoc"),
|
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.heredoc"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_folder_sink.heredoc",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,8 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,11 +14,16 @@ func resourceLoggingOrganizationSink() *schema.Resource {
|
||||||
Delete: resourceLoggingOrganizationSinkDelete,
|
Delete: resourceLoggingOrganizationSinkDelete,
|
||||||
Update: resourceLoggingOrganizationSinkUpdate,
|
Update: resourceLoggingOrganizationSinkUpdate,
|
||||||
Schema: resourceLoggingSinkSchema(),
|
Schema: resourceLoggingSinkSchema(),
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceLoggingSinkImportState("org_id"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["org_id"] = &schema.Schema{
|
schm.Schema["org_id"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
DiffSuppressFunc: optionalPrefixSuppress("organizations/"),
|
StateFunc: func(v interface{}) string {
|
||||||
|
return strings.Replace(v.(string), "organizations/", "", 1)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["include_children"] = &schema.Schema{
|
schm.Schema["include_children"] = &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
|
|
|
@ -31,6 +31,10 @@ func TestAccLoggingOrganizationSink_basic(t *testing.T) {
|
||||||
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.basic", &sink),
|
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.basic", &sink),
|
||||||
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.basic"),
|
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.basic"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_organization_sink.basic",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -63,6 +67,10 @@ func TestAccLoggingOrganizationSink_update(t *testing.T) {
|
||||||
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.update", &sinkAfter),
|
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.update", &sinkAfter),
|
||||||
testAccCheckLoggingOrganizationSink(&sinkAfter, "google_logging_organization_sink.update"),
|
testAccCheckLoggingOrganizationSink(&sinkAfter, "google_logging_organization_sink.update"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_organization_sink.update",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -97,6 +105,10 @@ func TestAccLoggingOrganizationSink_heredoc(t *testing.T) {
|
||||||
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.heredoc", &sink),
|
testAccCheckLoggingOrganizationSinkExists("google_logging_organization_sink.heredoc", &sink),
|
||||||
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.heredoc"),
|
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.heredoc"),
|
||||||
),
|
),
|
||||||
|
}, {
|
||||||
|
ResourceName: "google_logging_organization_sink.heredoc",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,7 +16,7 @@ func resourceLoggingProjectSink() *schema.Resource {
|
||||||
Update: resourceLoggingProjectSinkUpdate,
|
Update: resourceLoggingProjectSinkUpdate,
|
||||||
Schema: resourceLoggingSinkSchema(),
|
Schema: resourceLoggingSinkSchema(),
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: resourceLoggingProjectSinkImportState,
|
State: resourceLoggingSinkImportState("project"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
schm.Schema["project"] = &schema.Schema{
|
schm.Schema["project"] = &schema.Schema{
|
||||||
|
@ -103,18 +103,3 @@ func resourceLoggingProjectSinkDelete(d *schema.ResourceData, meta interface{})
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceLoggingProjectSinkImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
||||||
config := meta.(*Config)
|
|
||||||
|
|
||||||
loggingSinkId, err := parseLoggingSinkId(d.Id())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Project != loggingSinkId.resourceId {
|
|
||||||
d.Set("project", loggingSinkId.resourceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return []*schema.ResourceData{d}, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -69,3 +69,16 @@ func expandResourceLoggingSinkForUpdate(d *schema.ResourceData) *logging.LogSink
|
||||||
}
|
}
|
||||||
return &sink
|
return &sink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceLoggingSinkImportState(sinkType string) schema.StateFunc {
|
||||||
|
return func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
|
loggingSinkId, err := parseLoggingSinkId(d.Id())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set(sinkType, loggingSinkId.resourceId)
|
||||||
|
|
||||||
|
return []*schema.ResourceData{d}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -69,3 +69,11 @@ exported:
|
||||||
|
|
||||||
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
||||||
configured `destination`.
|
configured `destination`.
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
Billing account logging sinks can be imported using this format:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ terraform import google_logging_billing_account_sink.my_sink billingAccounts/{{billing_account_id}}/sinks/{{sink_id}}
|
||||||
|
```
|
||||||
|
|
|
@ -79,3 +79,11 @@ exported:
|
||||||
|
|
||||||
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
||||||
configured `destination`.
|
configured `destination`.
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
Folder-level logging sinks can be imported using this format:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ terraform import google_logging_folder_sink.my_sink folders/{{folder_id}}/sinks/{{sink_id}}
|
||||||
|
```
|
||||||
|
|
|
@ -73,3 +73,11 @@ exported:
|
||||||
|
|
||||||
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
* `writer_identity` - The identity associated with this sink. This identity must be granted write access to the
|
||||||
configured `destination`.
|
configured `destination`.
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
Organization-level logging sinks can be imported using this format:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ terraform import google_logging_organization_sink.my_sink organizations/{{organization_id}}/sinks/{{sink_id}}
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user